Convert XAML WPF Window to WinForm

前端 未结 3 392
野性不改
野性不改 2021-01-24 07:03

Is there any utility or converter to convert XAML WPF window to .Net 2.0 Windows forms form?

3条回答
  •  自闭症患者
    2021-01-24 07:42

    There is no tool to convert it across. It might be worth using an ElementHost to load WPF components in WPF, that way you don't need to convert and can re-use WPF components. If you have a WPF window you would need to convert this to a UserControl to work.

    EDIT:

    .Net 2 code to load WPF control

        string dllPath = "C:\\ProjectsTest\\TestSolution\\ActiveXUser\\bin\\Debug\\TestControl.dll";
    if (!File.Exists(dllPath)) {
        return;
    }
    
    string versionInformation = null;
    versionInformation = Environment.Version.Major.ToString() + Environment.Version.Minor;
    
    Assembly loadedAssembly = Assembly.LoadFile(dllPath);
    
    Type[] mytypes = loadedAssembly.GetTypes();
    
    Type t = mytypes[1];
    Object obj = Activator.CreateInstance(t);
    
    versionInformation = Environment.Version.Major.ToString() + Environment.Version.Minor;
    this.Panel1.Controls.Add(obj);
    

提交回复
热议问题