我有以下路由事件:
public static readonly RoutedEvent FakeEvent = EventManager.RegisterRoutedEvent(
"Fake", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(MainWindow));
public event RoutedEventHandler Fake
{
add { AddHandler(FakeEvent, value); }
remove { RemoveHandler(FakeEvent, value); }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(MainWindow.FakeEvent);
RaiseEvent(newEventArgs);
}
我有以下 XAML:
<Window.Resources>
<Style TargetType="{x:Type TextBlock}"
xmlns:local="clr-namespace:WpfApplication1">
<Setter Property="Margin" Value="10" />
<Setter Property="Background" Value="Red" />
<Style.Triggers>
<EventTrigger RoutedEvent="local:MainWindow.Fake">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="Blue" Duration="0:0:1"
Storyboard.TargetProperty="Background.Color" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<Button Click="Button_Click">Raise Event</Button>
<TextBlock>Hello World</TextBlock>
<TextBlock>Hello World</TextBlock>
<TextBlock>Hello World</TextBlock>
<TextBlock>Hello World</TextBlock>
<TextBlock>Hello World</TextBlock>
<TextBlock>Hello World</TextBlock>
</StackPanel>
我的目标是通过使用可重用的通用样式,窗口的路由事件将导致情节提要为所有 TextBlock 触发。但是,引发路由事件(通过单击按钮)不会导致任何事情发生(没有错误,只是什么都没有)。不知道出了什么问题。
对此的正确方法是什么?