C# 鼠标按下事件未触发(冒泡事件)

C# 鼠标按下事件未触发(冒泡事件),c#,.net,wpf,.net-4.0,C#,.net,Wpf,.net 4.0,我是WPF的新手。我开始学习WPF中的RoutedEvents。我试了一个样品,但遇到了一个问题 <Grid Margin="5" Name="Grid" MouseDown="Window_MouseUp"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"></RowDefinitio

我是WPF的新手。我开始学习WPF中的RoutedEvents。我试了一个样品,但遇到了一个问题

    <Grid Margin="5" Name="Grid" MouseDown="Window_MouseUp">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Label BorderBrush="Black" BorderThickness="1" Grid.Row="0" Margin="5"        Name="FancyLabel" MouseDown="Window_MouseUp" >
        <StackPanel Name="Stack" MouseDown="Window_MouseUp"> 
            <TextBlock Margin="3" Name="txtBlock1">
                Click Any Where
            </TextBlock>
            <TextBlock Margin="50" Name="txtBlock2" >
                Click me also
            </TextBlock>
        </StackPanel>
    </Label>
    <ListBox Grid.Row="1" Margin="5" Name="ListMessages"/>
    <Button Grid.Row="3" Margin="5" Name="cmd_Clear" MouseDown="Cmd_Clear_MouseDown"  >Clear</Button>
</Grid>
Cmd_Clear_MouseDown事件被触发,事件被冒泡到网格中,网格触发窗口\u MouseUp。

两点:

1) 是否打算在任何地方使用
MouseDown=“Window\u MouseUp”

2) 为什么不注册到
ClickMode=“Press”
而不是
MouseDown
点击
事件。我不认为
按钮
提供/提升
鼠标向下
,除非可能使用自定义模板

例子:
清除
两点:

1) 是否打算在任何地方使用
MouseDown=“Window\u MouseUp”

2) 为什么不注册到
ClickMode=“Press”
而不是
MouseDown
点击
事件。我不认为
按钮
提供/提升
鼠标向下
,除非可能使用自定义模板

例子:
清除
 Grid.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp),true);
 Stack.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp), true);
 FancyLabel.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp), true);
 txtBlock1.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp), true);
 txtBlock2.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp), true);
 Img1.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Window_MouseUp), true);
 cmd_Clear.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(Cmd_Clear_MouseDown), true);
<Button Grid.Row="3"
        Margin="5"
        Name="cmd_Clear"
        ClickMode="Press"
        Click="Cmd_Clear_MouseDown">Clear</Button>