将xaml文件添加到Windows froms Project中 [英] add a xaml file to my windows froms Project

查看:340
本文介绍了将xaml文件添加到Windows froms Project中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.xaml文件,我想将其添加到我现有的Windows窗体项目中.我可以那样做吗?我怎样才能做到这一点?

(当我尝试这样做时,它给了我编译错误)


Kushan Randima

I have a .xaml file and I want to add it to my existing windows forms project. Can I do that? How can I do that?

(When I try to do it, it gave me compile errors)


Kushan Randima

推荐答案

XAML格式可用于WPF/Silverlight.
Windows窗体仅将.cs文件用于UI元素的定义.

因此,答案是否定的:您不能按原样在WinForms项目中添加XAML文件.您必须创建一个新的System.Windows.Forms.Form,以模仿您的XAML文件的外观.
XAML format is for use with WPF/Silverlight.
Windows Forms uses only .cs files for the definition of UI elements.

So, the answer is no : you cannot add an XAML file in a WinForms project as is. You have to create a new System.Windows.Forms.Form that will mimic the look of your XAML file.


您可以将.XAML文件添加到项目中,就像添加其他任何文件一样,但是请为沮丧:不会将WPF窗口添加到您的Forms应用程序.您了解WPF应用程序的性质有很大不同吗?它与Windows API 几乎没有关系吗?

Forms和WPF之间可以进行互操作,但是非常复杂.请参阅:
http://msdn.microsoft.com/en-us/library/ms751797.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms742215.aspx [ ^ ].

原则上,XAML与WPF不直接相关.这只是一个XML模式,可以用于许多不同目的.例如,您可以将XAML用作矢量图像格式.在这种情况下,您可以将其作为资源包含在Forms(或任何其他)项目中,并用于某些图形目的.不知何故-您没有与我们分享您的目标.您可以创建一些引擎来处理XAML图形或其他内容.

—SA
You can add a .XAML file to your project exactly as any other file, but prepare for the frustration: it won''t add a WPF Window to your Forms application. Do you understand that the nature of WPF application is very different; and it has almost nothing to do with Windows API?

Interoperation between Forms and WPF is possible, but quite complex. Please see:
http://msdn.microsoft.com/en-us/library/ms751797.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx[^],
http://msdn.microsoft.com/en-us/library/ms742215.aspx[^].

In principle, XAML is not directly related to WPF. This is just an XML schema which could be used for many different purposes. For example, you can use XAML as a vector image format. In this case, you can include it in your Forms (or any other) project as a resource and use for some graphical purposes. Somehow — you did not share with us your purposes. You could create some engine to work with XAML graphics or something.

—SA


这篇关于将xaml文件添加到Windows froms Project中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆