listview - 如何在 ListView 中获取复选框的坐标
问题描述
在我的项目中,我有一个 ListView,里面有很多复选框。为了一次选中和取消选中它们的选择,我实现了在画布 (dragSelectionCanvas) 内绘制矩形 (dragSelectionBorder) 的功能,与此处所做的非常相似:https ://www.codeproject.com/Articles /148503/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;
}
我希望你能帮我解决这个问题,因为我现在挣扎了好几个小时。
谢谢,
马丁
解决方案
推荐阅读
- regex - How to filter android logcat by exact word and space between words?
- react-native - Flatlist collapse/expand not working in React-Native
- python - 如何从python中的文件名中提取时间戳?
- javascript - 如何使用javascript中的时区名称和区域查找UTC中的时区偏移量
- c++ - ClangTool如何在变量声明中获取模板参数的位置?
- javascript - Angular HttpClient observable 未完成
- python - 使用'for循环'
- sql - SQL - 使用变量访问数据库
- java - 在 Spring Boot 中重新加载/刷新缓存
- vhdl - 如何写入控制台自定义数组类型