如何在wpf xaml mvvm的listview中编写基于命令的moused双击记录事件

时间:2015-03-18 14:06:21

标签: wpf mvvm

如何为customerresultlistview添加双击鼠标事件,此时正常点击滚动鼠标,应该双击并将其设置为选择按钮

<ScrollViewer x:Name="scrollViewer" Focusable="False"
              VerticalScrollBarVisibility="Visible" Grid.Row="1"
              HorizontalScrollBarVisibility="Hidden">

    <ListView x:Name="CustomerResultListView"
              ItemsSource="{Binding Segments[CustomerLookupSegment].Items[SearchResult].SegmentObject, Mode=TwoWay}"
              Focusable="False" SelectionMode="Single" BorderThickness="0"
              SelectionChanged="CustomerResultListView_SelectionChanged">
        <ListView.View>
            <GridView x:Name="CustomerResultGridView">
                <GridView.ColumnHeaderContainerStyle>
                    <Style TargetType="{x:Type GridViewColumnHeader}">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Style>
                </GridView.ColumnHeaderContainerStyle>

1 个答案:

答案 0 :(得分:0)

2种方式:

<ListView ItemsSource="{Binding Items}">
        <ListView.InputBindings>
            <MouseBinding Gesture="LeftDoubleClick" Command="{Binding MyListViewCommand}"/>
        </ListView.InputBindings>
        <ListView.ItemTemplate>
            <DataTemplate DataType="{x:Type local:Item}">
                <TextBlock Text="{Binding Text}">
                    <TextBlock.InputBindings>
                        <MouseBinding Gesture="LeftDoubleClick" Command="{Binding MyItemCommand}"/>
                    </TextBlock.InputBindings>
                </TextBlock>
            </DataTemplate>
        </ListView.ItemTemplate>            
    </ListView>

或者将偶数绑定到命令:

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

<ListView>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SomeEvent">
            <i:InvokeCommandAction Command="{Binding Path=SomeCommand, Mode=OneWay}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>

</ListView>