StackWnel的MouseWheel EventToCommand

时间:2015-07-22 14:20:32

标签: c# wpf mvvm mvvm-light

我有一个带有Listview的StackPanel。 我希望能够在窗口内滚动,以更改selectedItem。

澄清; 我想在滚动鼠标滚轮时更改我的ViewModels SelectedItem。

我找不到通过EventToCommand

将命令绑定到事件的方法

我认为可以通过

来取消它
.bind(variable)

但是这给我一个错误,说明eventtrigger只能被绑定到UIElement。

然后我尝试了ListView - 它也没有用。

如何将事件(带有args)绑定到滚轮事件?

1 个答案:

答案 0 :(得分:2)

我认为你几乎就在那里,但是你需要将你的EventTrigger包装在System.Windows.Interactivity Interaction类中:

<StackPanel>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseWheel">
            <cmd:EventToCommand PassEventArgsToCommand="True" 
                  Command="{Binding MouseScrollCommand}">
            </cmd:EventToCommand >
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ListView/>
</StackPanel>

您应该会发现会引发事件,然后调用您的命令。

Interaction类处理关联对象上的事件,并通过EventTriggers传播它们。

相关问题