我得到了一个ListView如下所示。用户应该选择一些项目,然后将DropDrop拖到其他地方。这不需要CTRL + click即可。但是,在完成所有选择之后,当我尝试开始拖动时,单击鼠标左键会取消选择被单击的项目。如何使它的行为类似于Windows资源管理器,所以当我用鼠标开始拖动时,选择不会改变。我浪费了很多时间,尝试了一些自称的解决方案,比如将ListView和ListViewItem都子类化,并弄混了PreviewMouseLeftButtonDown,但对我没有任何帮助。 TIA!
<ListView SelectionMode="Multiple" Grid.Column="1" >
<ListView.View>
<GridView>
<GridViewColumn Width="25">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem, AncestorLevel=1}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="200" />
</GridView>
</ListView.View>
<ListView.Items>
<ListViewItem>1 - The one and only</ListViewItem>
<ListViewItem>2 - The second and only</ListViewItem>
<ListViewItem>3 - The third and only</ListViewItem>
<ListViewItem>4 - The 4th and only</ListViewItem>
<ListViewItem>5 - The 5th and only</ListViewItem>
<ListViewItem>6 - The 6ht and only</ListViewItem>
</ListView.Items>
</ListView>
最佳答案
我只是碰巧回答here,并且效果很好。感谢那里的所有人!
关于wpf - 在开始拖动之前,ListView丢失选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3887624/