我正试图在我的winform上托管一个wpf控件(网格视图)。
我正在使用elementHost在我的winform上创建wpf控件。
当我想要向wpf控件添加行时,如何创建事件?
发布于 2015-11-18 15:37:23
将网格视图包装在用户控件中,并在用户控件中处理事件。请注意,当您托管一个适用于我的wpf control.Solution时,某些事件将不会被调用:在加载和elementhost获得焦点时,将焦点设置为您的用户控件。
发布于 2015-11-18 15:52:55
在Winforms中订阅WPF控件的事件与其他事件相同。只需获取WPF控件实例并使用以下代码:
wpfbutton1.Click += new RoutedEventHandler(wpfbutton1_Click);
void wpfbutton1_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}示例代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ElementHost host = new ElementHost() { Dock = DockStyle.Fill };
this.Controls.Add(host);
System.Windows.Controls.Button wpfButton =
new System.Windows.Controls.Button() { Content = "WPF Button" };
host.Child = wpfButton;
wpfButton.Click += new System.Windows.RoutedEventHandler(wpfButton_Click);
}
void wpfButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
MessageBox.Show("Button is clicked");
}
}https://stackoverflow.com/questions/33757391
复制相似问题