2015-01-20 2 views
1

ListItemTemplate이있는 Listbox가 있습니다. 각 목록 항목에 첨부하려는 두 개의 명령이 있습니다.WPF DataTemplate previewmouseleftbuttonup이 작동하지 않습니다.

1) PreviewMouseLeftButtonDown : 드래그 앤 드롭 기능을 사용하는 경우에도이 기능을 사용합니다. 사용자 누르기 버튼 이벤트가 시작되고 사용자가 드래그하도록 선택한 항목의 수를 알게되었습니다.

2) PreviewMouseLeftButtonUp : 사용자가 목록 항목에서 마우스를 놓을 때 사용하고 싶습니다. (그러나 문제는 심지어 해고 결코 극복이있다. 그것은 모두 장악 첫번째 이벤트처럼 보인다. 여기에

내 코드. Pls는 도움이됩니다. 당신의 드래그하려고 노력하는 것처럼

<DataTemplate x:Key="ListItemTemplate"> 
    <Grid Margin="0" Width="58" Height="58" x:Name="OuterGrid">   
     <Border x:Name="OuterBorder" BorderBrush="{DynamicResource ContentToGreyedOutBrush}" BorderThickness="0" Margin="0" Background="Transparent" Grid.Column="0" Grid.Row="0" 
             ClipToBounds="True" CornerRadius="0"> 
      <Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="1" Margin="0" Background="Transparent" CornerRadius="0"> 
       <Grid> 
        <Image Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding Path=FileName,Converter={StaticResource FileNameImageConverter}}" 
            Width="50" Height="50"> 
        </Image> 
        <ToggleButton x:Name="zoomButton" Grid.Column="0" Grid.Row="0" Margin="0" HorizontalAlignment="Right" HorizontalContentAlignment="Right" VerticalAlignment="Bottom" 
          VerticalContentAlignment="Bottom" Background="Transparent" Cursor="Hand" Template="{StaticResource ZoomTemplate}" Width="20" Height="20" Visibility="Collapsed"> 
        </ToggleButton> 
       </Grid> 
      </Border> 
     </Border> 
     <ac:CommandBehaviorCollection.Behaviors> 
      <ac:BehaviorBinding Event="PreviewMouseLeftButtonDown" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}},Path=DataContext.DragItemSelectedCommand}" 
           CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}"/> 

    <ac:BehaviorBinding Event="PreviewMouseLeftButtonUp" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}},Path=DataContext.MouseUPCommand}" 
           CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}"/> 
     </ac:CommandBehaviorCollection.Behaviors> 
</Grid> 
</DataTemplate> 
+1

미리보기의 터널링 부분은 목록 상자 항목에 도달하기 전에 목록 상자에서 처리됩니다. 이유는 무엇입니까? 일반이 아닌보기? –

답변

0

것 같습니다 드래그를 시작한 컨트롤이 아니라 마우스를 놓았을 때 새 컨트롤에서 위로 이벤트가 발생합니다.이 작업을 수행하려면 다음을 수행해야합니다. 드래그 작업을 시작할 때 마우스를 캡처해야합니다.