这是场景:
我有以下用户控件,其想法是其视图模型应该能够向视图发信号以表明它需要“激活 Glow”,从而播放 Storyboard。
<UserControl x:Class="View.UnitView" ... >
...
<Storyboard x:Key="ActivateGlow">
...
</Storyboard>
...
<!-- INVALID BINDING! Not Dependancy Object-->
<EventTrigger RoutedEvent="{Binding OnActivateGlow}">
<BeginStoryboard Storyboard="{StaticResource ActivateGlow}"/>
</EventTrigger>
</UserControl>
在 UnitView 的后端代码中,我有以下内容:
public event EventHandler ActivateGlow;
而在MVVM中非常常见的是,我有以下的DataTemplate用于UnitViewModel:
<DataTemplate DataType="{x:Type vm:UnitViewModel}">
<vw:UnitView d:DesignWidth="150" d:DesignHeight="100" />
</DataTemplate>
最重要的问题是,我如何设置某些内容,以便视图模型可以触发OnActivateGlow事件?