Convert XAML WPF Window to WinForm

百般思念 提交于 2019-12-02 10:33:07

问题


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


回答1:


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.




回答2:


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);



回答3:


Maybe you could use this Xaml library for WinForms?

https://winformsxaml.codeplex.com



来源:https://stackoverflow.com/questions/5008082/convert-xaml-wpf-window-to-winform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!