【发布时间】:2011-11-07 12:41:37
【问题描述】:
我在 XAML 端获得了以下解决方案,将事件绑定到命令,效果很好。
参考文献
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
按钮定义:
<Button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter" >
<i:InvokeCommandAction Command="{Binding FooCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
问题: 现在我需要在 code behind 中为我的对象做同样的事情,这是一个 FrameworkElementFactory 但我想不通,我想也许有人可以帮助我。
这里是我停下来的地方:
FrameworkElementFactory newLabel = new FrameworkElementFactory(typeof(Label));
newLabel.SetValue(Label.BackgroundProperty, Brushes.DarkMagenta);
var eventTrigger = new System.Windows.Interactivity.EventTrigger("MouseDown");
var invokeCommandAction = new System.Windows.Interactivity.InvokeCommandAction()
{
CommandName = "FooCommand",
CommandParameter = new Object()
};
有什么帮助吗?
提前致谢, 法扎德
【问题讨论】:
标签: wpf events binding mvvm command