【发布时间】:2018-01-17 14:06:59
【问题描述】:
我已经创建了一个这样的自定义 WPF 控件:
我将此 WPF 控件放置在我的 Form1(Windows 窗体)中并为其编写了一个事件 MouseEnter。我在这里期望的是在 WPF 控件中获取按钮的名称。我在 Form1 中只使用了 1 个 WPF 控件。但我在 Form1 中有 24 个 WPF 控件。我使用 foreach 循环遍历所有 ElementHost (WPF 控件)并将每个 ElementHost 的子项转换为 WPF 控件。我在将 ElementHost 转换为 WPF 控件时遇到问题。
这是我的代码:
public Form1()
{
InitializeComponent();
foreach (ElementHost c in this.Controls)
{
TP1WPFControls.TP1CustomButton bt = c.Child as TP1CustomButton;
bt.bt.MouseEnter += Bt_MouseEnter;
bt.bt.MouseLeave += Bt_MouseLeave;
}
//TP1WPFControls.TP1CustomButton btnCustom = elementHost1.Child as TP1CustomButton;
//btnCustom.bt.Click += Bt_Click;
//btnCustom.bt.MouseEnter += Bt_MouseEnter; ;
//btnCustom.bt.MouseLeave += Bt_MouseLeave; ;
}
希望大家可以给我一个解决方案。
谢谢!
【问题讨论】:
标签: c# winforms wpf-controls