Converting dll with WinForm application to WPF

Viewed 25

I need to convert existing plugin for CAD systems from WinForm based UI to WPF. The plugin is a basic dll library with Main method used by main application as an entry point to call this plugin. Also it includes a couple of mandatory methods to load/unload the library with plugin. Long story short. How it looks today (WinForm based):

public class MyPluginClass : System.Windows.Forms.Form
{
    private static MyPluginClass thePlugin;

    public MyPluginClass()
    {
        InitializeComponent();           
        // Make the displayed window a child of the main application window
        Reparent(this);
    }

    private void InitializeComponent()
    {
        //UI initialization logic   
    }

    // The main entry point. Called when this library is loaded
    public static void Main() 
    {
        thePlugin = new MyPluginClass();
        thePlugin.Show();
    }
}

Once I load this dll, the parent app executes the Main methods and I get the plugin form loaded and displayed.

Now I'm trying to use WPF instead of WinForm (and I have zero experience in WPF, so apologize for silly questions if any). First thing I tried is to apply the same logic I used with WinForms - just extend Window class:

public class MyPluginClass : Window
    {
        private static MyPluginClass thePlugin;        
        .....
        public static void Main() 
        {
            thePlugin = new MyPluginClass();
            thePlugin.Show();
        }
    }

...and I didn't find the way to load required XAML file with my window layout. While trying to find solution, I read several posts saying that maybe it's not a good approach to create derived class based on Window. Though, examples I found so far, describe the standalone application (.exe), while in my case I'm trying to invoke WPF UI while being inside the dll file called by parent application. Is there a way to specify the required XAML file in this case (when I derive my class from Window class) or I'm going completely wrong way?

0 Answers
Related