我可以在WPF中使用InputBindings启用PreviewClick吗? [英] Can I enable PreviewClick using InputBindings in WPF?

查看:251
本文介绍了我可以在WPF中使用InputBindings启用PreviewClick吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户何时单击列表视图上的项目,而不用像命令绑定那样使用事件,并且我不喜欢所有无用的行为.我已经尝试过了:

I want to detect when a user clicks on an item on a listview, without using events as I do command binding and I don't like all the nonsense of the behaviours. I have tried this:

<ListView x:Name="MainList" Margin="2,8,6,8" Background="Black" 
   ItemsSource="{Binding Path=AssetsVM.Data, Mode=OneWay}" 
   BorderBrush="{x:Null}" >

    <ListView.InputBindings>
         <MouseBinding Command="{Binding Path=AssetsVM.SelectActivo}" 
            CommandParameter="{Binding ElementName=MainList, Path=SelectedItem}" 
            MouseAction="LeftClick" />
    </ListView.InputBindings>

如果我单击列表视图,但不适用于这些项目,则此方法工作正常.我需要的是启用预览"的方法或具有充当预览功能的MouseAction/Gesture.这些可能是其中一种吗?

This works fine if I click on the listview but does not work on the items. What I need is either a way to enable "Preview" or have a MouseAction/Gesture that behaves as preview. Are either one of these possible?

推荐答案

在使用像这样的命令驱动的体系结构时,我通常使用

When using a command-driven architecture like this, I usually use AttachedCommandBehavior to get around the fact that Microsoft did not make MouseBinding.Command a DependencyProperty. An example of how to do get the functionality you want using this approach is shown below:

<ListView x:Name="MainList" ItemsSource="{Binding Path=AssetsVM.Data, Mode=OneWay}">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Style.Setters>
                <Setter Property="acb:CommandBehavior.Event" Value="Selected" />
                <Setter Property="acb:CommandBehavior.Command" Value="{Binding DataContext.AssetsVM.SelectActivo, ElementName=MainList}" />
                <Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding}" />
            </Style.Setters>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

这篇关于我可以在WPF中使用InputBindings启用PreviewClick吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆