我可以从 winform 中的 WPF 组合框捕获事件吗?
我已经在 winform 中实现了一个 wpf 组合框,现在必须以某种方式使其在更改框时调用我的 winform 中的函数或事件,并且能够更改 winform 中的值。
main:
namespace main
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ElementHost elhost = new ElementHost();
elhost.Size = new Size(174, 24);
elhost.Location = new Point(93,60);
MyWPFControl wpfctl = new MyWPFControl();
elhost.Child = wpfctl;
this.Controls.Add(elhost);
elhost.BringToFront();
}
public void status_change(int val)
{
MessageBox.Show("Box value has changed to:" + Convert.ToString(val) );
}
和wpf:
namespace main
{
/// <summary>
/// Interaction logic for MyWPFControl.xaml
/// </summary>
public partial class MyWPFControl : UserControl
{
public MyWPFControl()
{
InitializeComponent();
}
private void statComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
main.status_change(statComboBox.SelectedIndex);
/// says:
/// Error 1 The type or namespace name 'status_change' does not exist in the namespace 'main' (are you missing an assembly reference?) C:\Users\Robert\documents\visual studio 2010\Projects\XMPP\main\wpf_combo_status.xaml.cs 31 18 main
}
}
}
知道我可能做错了什么吗?谢谢!
I had implemented a wpf combobox into a winform and now have to somehow make it call a function or an event in my winform when the box is changed, as well as be able to change the value from the winform.
main:
namespace main
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ElementHost elhost = new ElementHost();
elhost.Size = new Size(174, 24);
elhost.Location = new Point(93,60);
MyWPFControl wpfctl = new MyWPFControl();
elhost.Child = wpfctl;
this.Controls.Add(elhost);
elhost.BringToFront();
}
public void status_change(int val)
{
MessageBox.Show("Box value has changed to:" + Convert.ToString(val) );
}
and wpf:
namespace main
{
/// <summary>
/// Interaction logic for MyWPFControl.xaml
/// </summary>
public partial class MyWPFControl : UserControl
{
public MyWPFControl()
{
InitializeComponent();
}
private void statComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
main.status_change(statComboBox.SelectedIndex);
/// says:
/// Error 1 The type or namespace name 'status_change' does not exist in the namespace 'main' (are you missing an assembly reference?) C:\Users\Robert\documents\visual studio 2010\Projects\XMPP\main\wpf_combo_status.xaml.cs 31 18 main
}
}
}
any idea what I might be doing wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
MyWPFControl
中公开一个事件,例如:然后在您的表单中订阅它,例如:
PS:
我无法测试它,因此可能会出现一些错误,但只是为了给出你的想法...;)
Expose an event in
MyWPFControl
like:Then subscribe it in your form, like:
P.S.:
I can't test it, so there could be some errors, but just to give you the idea... ;)
如果没有更多上下文,很难说,但您想要的代码似乎可能是:
假设
main
是您要调用的
。Form1
实例status_changeIt's hard to say without more context, but it would seem that the code you want is probably:
Assuming
main
is the instance ofForm1
on which you want to callstatus_change
.