可能的重复:
如何在样式设置器中添加混合行为 https://stackoverflow.com/questions/1647815/how-to-add-a-blend-behavior-in-a-style-setter
当我在样式中使用交互触发器时,出现以下错误:“触发器不是样式类型的可附加元素”。任何解释这个错误的实际含义以及如何解决它。
作为参考,请查看 MVVM Light 工具包的 EventToCommand 示例。
在这种特殊情况下,我使用 Infragistics 中的 Timeline 控件,它将事件表示为 EventTitle,当单击 EventTitle 时,我想发出命令(请注意,Timeline 控件没有定义任何类似 EventTitleClicked 的事件)。目前,我可以通过使用事件并从后面的代码调用我的 ViewModel 方法来实现该功能,而不是我想直接从 xaml 调用该命令。
<Style x:Key="EventTitleTopStyle" TargetType="igTl:EventTitle">
<!-- The following is not working -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<!--<cmd:EventToCommand Command="{Binding MyCommand}" />-->
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- Using event setter instead to achieve the same -->
<EventSetter Event="MouseLeftButtonDown" Handler="TopTitleMouseLeftButtonDown" />
....
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="MouseDoubleClick">
<behaviours:ExecuteCommandAction Command="{Binding Path=DataContext.YourCommand, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding }"/>
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)