这是场景:
我有以下用户控件,想法是它的视图模型应该能够向视图发出信号,它需要"激活发光",从而播放故事板.
<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>
Run Code Online (Sandbox Code Playgroud)
在UnitView的代码隐藏中,我有:
public event EventHandler ActivateGlow;
Run Code Online (Sandbox Code Playgroud)
并且在MVVM中非常正常,我为UnitViewModel提供了以下DataTemplate:
<DataTemplate DataType="{x:Type vm:UnitViewModel}">
<vw:UnitView d:DesignWidth="150" d:DesignHeight="100" />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
最后一个问题是,我如何设置一些东西,以便viewmodel可以触发OnActivateGlow事件?