我有List4和ListItemTemplate。我希望每个列表项附加两个命令。
1)PreviewMouseLeftButtonDown:即使用于拖放功能,我也会使用它。用户按下按钮事件被触发,我开始知道用户选择拖动的项目数。
2)PreviewMouseLeftButtonUp:我想在用户从列表项中释放鼠标时使用它。 (但问题是,这甚至永远不会被解雇。看起来第一事件控制了两者。
这是我的代码。请帮助。
<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>
答案 0 :(得分:0)
您似乎正在尝试将项目拖动到原始边界之外的其他位置。在这种情况下,up事件将触发释放时鼠标所在的新控件,而不是您开始拖动的控件。要完成这项工作,您需要确保在开始拖动操作时捕获鼠标。