c# wpf代码怎么嵌入EXE应用程序

c# wpf代码怎么嵌入EXE应用程序,第1张

在 C# WPF 中嵌入 EXE 应用程序方法有多种。一种方法是使用 Process 类并调用其 Start 方法来启动 EXE 应用程序,然后使用 WindowInteropHelper 类来将 EXE 应用程序窗口嵌入 WPF 窗口中。例如:

请注意,这只是一种可能的方法,并不一定适用于所有情况。如果您需要更详细的帮助,请提供更多信息,例如您的目标和限制。

这里建议你使用Binding来处理。

了解下ObservableCollection<T> 类和BindingList<T> 类。

ObservableCollection<T> 类

表示一个动态数据集合,在添加项、移除项或刷新整个列表时,此集合将提供通知。

具体说明参考MSDN文档:>

WPF的MainWindow的代码

using System;

using SystemCollectionsGeneric;

using SystemLinq;

using SystemText;

using SystemWindows;

using SystemWindowsControls;

using SystemWindowsData;

using SystemWindowsDocuments;

using SystemWindowsInput;

using SystemWindowsMedia;

using SystemWindowsMediaImaging;

using SystemWindowsNavigation;

using SystemWindowsShapes;

namespace WpfApplication2

{

/// <summary>

/// MainWindowxaml 的交互逻辑

/// </summary>

public partial class MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

UserControl1 us = new UserControl1();

thisgridChildrenAdd(usaddTextBox()); // 在前台的Grid里 添加Name属性,才可以使用 thisgrid例如<Grid Name="grid">

}

}

}

winform的userControl的代码

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemDrawing;

using SystemData;

using SystemLinq;

using SystemText;

using SystemWindowsForms;

using SystemWindowsControls;

namespace WpfApplication2

{

public partial class UserControl1 : SystemWindowsControlsControl

{

public UserControl1()

{

InitializeComponent();

}

private void UserControl1_Load(object sender, EventArgs e)

{

addTextBox();

}

public SystemWindowsControlsTextBox addTextBox()

{

SystemWindowsControlsTextBox tx = new SystemWindowsControlsTextBox();

txText = "111";

return tx;

}

}

}

UserControl1Designercs 这个不改的话,你执行下,报错的地方删掉

namespace WpfApplication2

{

partial class UserControl1

{

/// <summary>

/// 必需的设计器变量。

/// </summary>

private SystemComponentModelIContainer components = null;

#region 组件设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

}

#endregion

}

}

因为WPF和WINFORM的控件类型是不一样的,一个是controls里的,一个是forms里的,你在WPF里添加 的话,类型不同,参数不能转换

其实我这样用,已经用的不是WINFORM的控件了,相当于自己建个类,写个创建控件的方法而已

例如,可以打开 Window1xaml 或 UserControl1xaml。右击“工具箱”,从快捷菜单中选择“选择项”。“选择工具箱项”对话框随即打开。单击“WPF 组件”选项卡。在列表中,找到要使用的控件。如果列表中没有显示要使用的控件,请单击“浏览”按钮。在“打开”对话框中,导航到包含要使用的控件的程序集。选择该程序集并单击“打开”。该控件即显示在“选择工具箱项”对话框中。确保选中控件旁边的复选框,然后单击“确定”按钮。选中的控件将显示在“工具箱”中。将控件从“工具箱”拖动到设计图面。选中的控件随即出现在设计图面上。

一般C#winform有的控件WPF中会有,但如果要调用C#Winform中的COM

控件和ActiveX

控件WPF是不支持的,所以需要先建立一个Winform项目,新建一个用户控件,将你要调用的控件放在用户控件中,编译成dll然后让wpf来调用。

以上就是关于c# wpf代码怎么嵌入EXE应用程序全部的内容,包括:c# wpf代码怎么嵌入EXE应用程序、wpf 如何调用ObservableCollection<Model>中 model类里面的方法。、wpf中调用winform用户控件的方法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/zz/10110424.html

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

发表评论

登录后才能评论

评论列表(0条)

保存