1
我已閱讀帖子Button.MouseDown 接下來我要問另外1個問題。 我的XAML如下:WPF如何將事件傳遞給兄弟元素
<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個兄弟姐妹的所有事件也能達到其他。拋開
private void C3_MouseDown(object sender, MouseButtonEventArgs e)
{
C33.RaiseEvent(e);
}
作爲,我注意到你正在使用標籤來命名元素: