user1790875
user1790875

Reputation: 21

hosting WPF inside Windows Form giving issues - C#

I've created a .DLL in WPF. To use it in existing Windows Forms application I use ElementHost.

ElementHost eleHOst = new ElementHost();
UserWarps userWarps = new UserWarps();
eleHOst.Child = userWarps;
eleHOst.Dock = DockStyle.Fill;

UserWarps is in WPF .DLL which has been add-referenced. Now the file does lot of 3D manipulations. I'm also using Petzold.Media3D for 3D lines for wireframe modelling. Everything's working fine except that WireLines of Petzold.Media3D is not drawing any lines. If I reference the DLL from other WPF applications everything's fine, but hosting the UserControl of wpf in windows forms eliminates the lines/wireframes. Rest everything is perfect - MeshGeometry3D, Models, Visuals, functionalities etc.

Please suggest the way forward. could any alternative to ElementHost work? If it does then what is it?

Upvotes: 2

Views: 839

Answers (1)

akjoshi
akjoshi

Reputation: 15772

Adding answer originally added by OP in question as I don't want this question to be closed just because of that.

Petzold has mentioned here that hosting wpf in Windows forms causes the Wire frames to disappear. He also posts a work around which is very simple and worked perfectly:

NOTE: For reasons discussed in paragraph 5, these Wire classes will not work when you're hosting 3D in Windows Forms, or when you're trying to print a 3D scene. To make it work, try replacing the static OnRendering method in WireBase with the following:

static void OnRendering(object sender, EventArgs args)
{
    foreach (WireBaseAndUltimateParent wirebaseAndParent in listWireBases)
    {
        WireBase wirebase = wirebaseAndParent.wirebase;
        wirebase.OnRendering();
    }
}

Upvotes: 1

Related Questions