如何在WPF中调用Winform控件

如何在WPF中调用Winform控件,第1张

功能实现主要分三步:

1、添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows)、System.Windows.Forms.

2、在 XAML文件中添加两个引用(粗体部分):

<Window x:Class="CrossBowDemo.MainWindow"

xmlns:wfi ="clr-namespace:System.Windows.Forms.Integrationassembly=WindowsFormsIntegration"

xmlns:wf ="clr-namespace:System.Windows.Formsassembly=System.Windows.Forms"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

title="Hosting Windows Forms Control In WPF"

Height="300"

Width="650"

ResizeMode="NoResize"

Loaded="WindowLoadedHandler"

>

</Window>

3、在XAML编码区实现你想添加的控件

原文添加的是DataGridView控<wfi:WindowsFormsHost>

<wf:DataGridView x:Name="Dg" Dock="Fill" SelectionMode="FullRowSelect">

</wf:DataGridView>

</wfi:WindowsFormsHost>件:

wpf显示动态消息的一种方式是使用ListBox控件。将数据源设置为消息信息的绑定,然后创建ItemTemplate来渲染每个消息,

最后在Form_Load中调用数据更新方法来获取动态消息,并将其绑定到 ListBox 上,这样就可以即时更新ListBox中的消息了。

另外,在WPF中也可以使用GridView控件实现对动态消息的显示,主要 *** 作步骤也是进行数据源绑定,然后创建GridViewItemTemplate来渲染每个消息,

最后在Form_Load中调用数据更新方法来获取动态消息,并将其绑定到GridView中,即可实现动态消息显示功能。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11532323.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存