[英]WPF Not receiving routed events from user control
I have a UserControl
which acts as a custom button, but since I changed my namespaces around the routed click event no longer works. 我有一个充当自定义按钮的
UserControl
,但是由于更改了路由单击事件周围的命名空间,因此不再起作用。 Essentially my namespaces look something like this: 本质上,我的命名空间如下所示:
UI
UI.Controls
UI.Pages
I have a UI.Controls.CustomButton
which has a routed click event implemented something like: 我有一个
UI.Controls.CustomButton
,它具有一个路由的click事件,实现如下:
public static readonly RoutedEvent ClickEvent = EventManager.RegisterRoutedEvent(
"Click",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(CustomButton));
public event RoutedEventHandler Click
{
add { AddHandler(ClickEvent, value); }
remove { RemoveHandler(ClickEvent, value); }
}
private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Border_MouseEnter(sender, e);
RaiseClickEvent();
}
private void RaiseClickEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(Button.ClickEvent);
RaiseEvent(newEventArgs);
}
And I am trying to use it from within a UI.Pages.SomePage
like so: 我试图像这样在
UI.Pages.SomePage
使用它:
<controls:CustomButton Text="New..." Click="NewButton_Click"/>
public void NewButton_Click(object sender, RoutedEventArgs e)
{
//do something here
}
When I debug the application I see that RaiseEvent
inside my UI.Controls.CustomButton
is being hit, but the NewButton_Click
inside my UI.Pages.SomePage
is never called. 当我调试应用程序时,我看到
UI.Controls.CustomButton
内的RaiseEvent
被击中,但NewButton_Click
内的UI.Pages.SomePage
从未被调用。
This was working when everything was in the same namespace... am I missing something obvious? 当所有内容都在同一个命名空间中时,这是可行的……我缺少明显的东西吗? Thanks!
谢谢!
RoutedEventArgs newEventArgs = new RoutedEventArgs(Button.ClickEvent);
应该:
RoutedEventArgs newEventArgs = new RoutedEventArgs(CustomButton.ClickEvent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.