【发布时间】:2010-11-28 07:03:58
【问题描述】:
这是场景:
我有以下用户控件,其想法是它的视图模型应该能够向视图发出信号,它需要“激活发光”,从而播放故事板。
<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 中很正常,我有以下用于 UnitViewModel 的 DataTemplate:
<DataTemplate DataType="{x:Type vm:UnitViewModel}">
<vw:UnitView d:DesignWidth="150" d:DesignHeight="100" />
</DataTemplate>
最重要的问题是,我怎样才能设置一些东西以便视图模型可以触发 OnActivateGlow 事件?
【问题讨论】:
标签: wpf events mvvm eventtrigger