我基本上是在尝试关注 http://blog.functionalfun.net/2008/09/hooking-up-commands-to-events-in-wpf.html策略,将事件绑定(bind)到命令。
我有一个 ListView,我想在其中双击一行来启动一个 ICommand 实例。其上的 ListView 或 ListBoxItem 没有命令属性。这个问题(看起来)是通过使用附加属性解决的,但我个人仍然无法弄清楚如何在 ListView 上使用它。
我有一个“信号”集合,每个都有一个属性“名称”。
下面是我的 xaml 的一部分。
<ListView ItemsSource="{Binding Signals}" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="{models:ListBoxItemBehaviour.DoubleClickCommand}" Value="{Binding Command1}" />
</Style>
</ListBox.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Signal" DisplayMemberBinding="{Binding Name}" />
</GridView>
</ListView.View>
</ListView>
这不起作用。 ListBoxItemBehaviour 是一种行为的实现,按照上面的链接, Hook ListBoxItem.MouseDoubleClickEvent 事件。
我怀疑上面的错误很小,但对我来说并不明显。有什么建议么?
第一个错误是:“不支持嵌套类型:”..
最佳答案
在 ListView
您可以使用 InputBindings 来获取鼠标和键盘输入。
要将 MouseDoubleClick 绑定(bind)到您可以使用的命令
<ListView.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ListViewDoubleClickCommand}"/>
</ListView.InputBindings>
关于c# - ListView 中的 WPF、MVVM、EventBehaviourFactory,将事件绑定(bind)到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24693150/