C# WPF:单击Usercontrols后台不会触发

C# WPF:单击Usercontrols后台不会触发,c#,wpf,events,routing,mouseevent,C#,Wpf,Events,Routing,Mouseevent,我有一个WPF用户控件,它简化了,看起来像这样: <UserControl Name="NiceUserControl" MouseLeftButtonUp="NiceUserControl_MouseLeftButtonUp"> <Grid MouseDown="Grid_MouseDown"> <Border> <A lot Of Different Stuff like Buttons and Othe

我有一个WPF用户控件,它简化了,看起来像这样:

<UserControl Name="NiceUserControl" MouseLeftButtonUp="NiceUserControl_MouseLeftButtonUp">
    <Grid MouseDown="Grid_MouseDown">
        <Border>
           <A lot Of Different Stuff like Buttons and Other usercontrols>
        </Border>
    </Grid>
</UserControl>
但这只对我的用户控件上的文本框有帮助,比如说,背景仍然不会触发。 即使使用包含的网格中的PreviewMouse事件或MouseEvents也不行


注意:例如,我希望控件中的按钮具有自己的单击事件,但我希望它们也触发usercontrols单击事件。

这可能是因为您没有设置background属性

您需要将
UserControl
上的
Background
Grid
Border
设置为其他默认值,例如
Transparent
。否则它就不会被命中测试可见。@dkozl它实际上就这么简单。我没想过。谢谢伙计,太棒了!非常感谢。就这么简单-至少我现在知道路由事件是如何工作的:D@topograph请你把它标为已回答好吗?谢谢当然Stackoverflow说,我必须等几分钟才能标记它;)
        NiceUserControl.AddHandler(MouseDownEvent, new MouseButtonEventHandler(NiceUserControl_MouseDown), true);