2017-11-29 6 views
1

私はプログラムが一度正常に一度完了した後、グリッドからクリップボードにテキストブロックをコピーしようとしています。私はクリップボードにデータをコピーするSelectionChangedイベントを持っています。エディタに貼り付けてクリップボードに貼り付けるのではなく、うまくいきます。他のデータをクリップボードにコピーするよりも、私はプログラムに戻って、クリップボードにデータを再度コピーするためにマウスをダブルクリックします。 MouseDownまたはMouseLeftButtonClickイベントを使用したいのですが、動作させることができません。このシナリオでは一部のマウスイベントのみが機能しますか?MVVM ListBoxマウスクリックしていないがMouseDoubleClickが

<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> 

答えて

1

代わりPreviewMouseDownまたはPreviewMouseLeftButtonDownをキャプチャする必要があります。例えば

:これらはすでにListBoxItem自体によって処理されListBoxItemによって提起されているバブリングイベントですので、あなたが期待通りMouseDownMouseLeftButtonDownが機能しないこと

<i:EventTrigger EventName="PreviewMouseDown"> 
    <i:InvokeCommandAction Command="{Binding PreviewMouseDownCommand}" CommandParameter="{Binding ElementName=AddItemList2,Path=SelectedItem}" /> 
</i:EventTrigger> 

理由があります。アプリケーションでは

は、それだけで

PreviewMouseDownPreviewMouseLeftButtonDownは、まず移動ルート要素上で呼び出されトンネリングイベントでそれを発生させたオブジェクトに泡立ちルーティングイベントを処理するために非常に一般的です子要素を介して。通常は、のにルート要素(UserControlまたはWindow)を追加することで、そこでイベントを処理する機会が与えられます。

あなたはトンネリングについての詳細を読むことができます/ここにイベントをバブリング(もここで撮影した上で引用された声明):https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/routed-events-overview

+0

おかげで、とてもうまくいきました。私は上記のあなたのリンクを読むでしょう。 – coolercargo

関連する問題