2010-10-08 47 views
3

我得到了一个ListView像下面这样。用户应该选择一些项目并将drag拖放到其他地方。这不需要按CTRL +点击哪个是好的。但是在所有选择完成之后,当我尝试开始拖动时,左键单击将取消选中被点击的项目。我怎样才能使这个行为像Windows资源管理器,所以选择不会改变,当我用鼠标开始拖动。我浪费了很多时间,尝试了一些声称的解决方案,比如一个是子类ListView和ListViewItem,并与PreviewMouseLeftButtonDown混淆,但没有为我工作。 TIA!ListView开始拖动之前丢失选择

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

确保您的选择是在触发MouseUp或Click而不是MouseDown? – jeffora 2010-10-08 04:12:52

回答

1

我刚碰到答案here,工作很好。万分感谢那里的所有人!