MVVM ListBox鼠标点击不工作,但MouseDoubleClick是

时间:2017-11-29 04:57:05

标签: c# wpf xaml mvvm

我试图让我的程序在成功完成一次后将文本块从网格复制到剪贴板。我有一个SelectionChanged事件将数据复制到剪贴板我而不是去编辑器粘贴剪贴板,它工作正常。我将一些其他数据复制到剪贴板。我切换回程序并双击鼠标再次将数据复制到剪贴板。我想使用MouseDownMouseLeftButtonClick事件,但我似乎无法让它们发挥作用。在这种情况下只做一些鼠标事件吗?

<ListBox>
   <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="1">
                <StackPanel Orientation="Horizontal" ScrollViewer.CanContentScroll="True" Width="auto" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                    </Grid>
                    <TextBlock Width="130" Grid.Column="0" ScrollViewer.CanContentScroll="True" x:Name="TextSelected" Text="{Binding Description}" TextWrapping="Wrap"  Margin="5,0,10,0"  HorizontalAlignment="Stretch" />
                    <TextBlock Width="150" Grid.Column="1" ScrollViewer.CanContentScroll="True" x:Name="TextCommand" Text="{Binding Command}" Margin="0,0,10,0"  TextWrapping="Wrap"  HorizontalAlignment="Stretch" />
                    <TextBlock Width="200" Grid.Column="2" ScrollViewer.CanContentScroll="True" x:Name="TextLocation" Text="{Binding Location}" Margin="0,0,10,0"  TextWrapping="Wrap"  HorizontalAlignment="Stretch" />
                </StackPanel>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction Command="{Binding AddItemBtn}" CommandParameter="{Binding ElementName=AddItemList2,Path=SelectedItem}" />
        </i:EventTrigger>

        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding AddItemBtn}" CommandParameter="{Binding ElementName=AddItemList2,Path=SelectedItem}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ListBox>

0 个答案:

没有答案