Convert XAML WPF Window to WinForm

前端 未结 3 353
野性不改
野性不改 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:29

    No, and there's unlikely to be anything like this; WPF and WinForms are disparate frameworks, a WPF UI can't really be converted to a WinForms UI due to differences in UI composition, layout differences, different positioning systems, etc.

    0 讨论(0)
  • 2021-01-24 07:41

    Maybe you could use this Xaml library for WinForms?

    https://winformsxaml.codeplex.com

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题