ListView 在开始拖动之前丢失选择

发布于 2024-09-26 18:34:08 字数 1504 浏览 0 评论 0原文

我得到了一个如下所示的 ListView 。用户应该选择一些项目并将其拖放到其他地方。这不需要 CTRL+单击,这很好。但在完成所有选择后,当我尝试开始拖动时,左键单击将取消选择被单击的项目。如何使其行为像 Windows 资源管理器一样,以便当我开始用鼠标拖动时选择不会改变。我浪费了很多时间,尝试了一些声称的解决方案,比如将 ListView 和 ListViewItem 进行子类化并弄乱 PreviewMouseLeftButtonDown 但没有任何效果对我有用。蒂亚!

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

I got a ListView Like the following. The User is supposed to select some Items and dragDrop to somewhere else. This does not require CTRL+click which is good. but after all the selection are made, when I try to start drag, the left click un-selects teh item that got clicked. How can I make this behave like windows explorer, so the selection dont change when I start a drag with mouse. I wasted quite a bit of time, tried some claimed solutions out there, like one was to sub class both the ListView and ListViewItem and messing with the PreviewMouseLeftButtonDown but nothing has worked for me. 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-10-03 18:34:08

我刚刚碰到了答案 在这里,并且效果很好。非常感谢那里的所有人!

I just bumped into the answer here, and works nice. A zillion thanks to all the guys there!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文