我已经阅读了Button.MouseDown的帖子 ,接着我想再问 1 个问题。我的 XAML 如下:
<Window.Resources>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="BorderThickness" Value="5" />
<Setter Property="Padding" Value="10" />
<Setter Property="Background" Value="PaleGreen" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel Tag="Panel" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown">
<ContentControl BorderBrush="Red" Tag="C1" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown">
<ContentControl BorderBrush="Green" Tag="C2" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown">
<StackPanel Tag="Panel2" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown">
<ContentControl Content="Click Me" BorderBrush="Blue" Tag="C3" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown"/>
<ContentControl Content="Click Me2" BorderBrush="Blue" Tag="C33" PreviewMouseDown="PreviewMouseDown" MouseDown="MouseDown"/>
</StackPanel>
</ContentControl>
</ContentControl>
</StackPanel>
我的cs如下:
private void PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine(((FrameworkElement) sender).Tag + " Preview");
}
private void MouseDown(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine(((FrameworkElement) sender).Tag + " Bubble");
}
如何将鼠标向上/向下事件从 C3 传输到 C33?基本上,我希望 1 个兄弟姐妹的所有事件也能传递给其他人。