微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何获取ListView中复选框的坐标

如何解决如何获取ListView中复选框的坐标

在我的项目中,我有一个 ListView,里面有很多复选框。为了一次选中和取消选中它们,我实现了在画布 (dragSelectionCanvas) 中绘制矩形 (dragSelectionBorder) 的功能,与此处所做的非常相似:https://www.codeproject.com/Articles/148503/Simple-Drag-Selection-in-WPF

现在我想比较一下,ListView 中的哪些复选框(部分)在 dragSelectionBorder 中。对于dragSelectionBorder,可以相对于dragSelectionCanvas 访问Coords,但是如何获取CheckBoxes 的坐标呢? 我是否需要将我所有的 xaml 设计都设置成这样的 Canvas,还是不需要外层 Canvas?

<Window>
    <Canvas x:Name="IsThisCanvasNeeded?">
        <Grid 
            x:Name="TheGridContainingEverything">
            <ListView x:Name="ManyCheckBoxes"/>
            <Canvas
            x:Name="dragSelectionCanvas">
                <Border 
                     x:Name="dragSelectionBorder"/>
            </Canvas>
        </Grid>
    </Canvas>
</Window>

要检查每个 CheckBox,如果它在 dragSelectionBorder 内,我想循环遍历 ListView,就像这样。

foreach (var item in MyListView.Items)
            {
                var lvi = TipRackListViewTopLeft.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
                // Get the CheckBox that is in the lvi
                // get the coords of the CheckBox
                // generate a Rectangle out of the checkBox coords
                // if(SelectionRectangle.Contains(CheckBoxRectangle))
                         CheckBox.IsChecked = !CheckBox.IsChecked;
            }

我希望你能帮我解决这个问题,因为我现在挣扎了几个小时。

谢谢,

马丁

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。