110,534
社区成员
发帖
与我相关
我的任务
分享
private UIElement CurUI;
private void RegButton(Canvas can)
{
foreach (UIElement ctl in can.Children)
{
ctl.MouseDown += ctl_MouseDown;
}
}
void ctl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
CurUI=sender as UIElement ;
}
[/quote]
这个应该可以吧,[/quote]
获取的CurUI为空null
private UIElement CurUI;
private void RegButton(Canvas can)
{
foreach (UIElement ctl in can.Children)
{
ctl.MouseDown += ctl_MouseDown;
}
}
void ctl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
CurUI=sender as UIElement ;
}
[/quote]
这个应该可以吧,
private UIElement CurUI;
private void RegButton(Canvas can)
{
foreach (UIElement ctl in can.Children)
{
if (ctl is Button)
{
ctl.MouseDown += ctl_MouseDown;
}
}
}
void ctl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
CurUI=sender as UIElement ;
}
private Button SelButton;
private void RegButton()
{
Canvas can = new Canvas();
foreach (UIElement ctl in can.Children)
{
if (ctl is Button)
{
ctl.MouseDown += ctl_MouseDown;
}
}
}
void ctl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
SelButton=sender as Button;
}
然后在你的菜单事件中访问selbutton就可以了啊