根据 WPF 中的索引在 UniformGrid 中查找子行和列 [英] Finding a childs row and column in UniformGrid based on Index in WPF
本文介绍了根据 WPF 中的索引在 UniformGrid 中查找子行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 WPF 中,我有一个统一网格,希望能够根据子元素的索引找到行和列.
In WPF, I have a Uniform Grid and would like to be able to find the row and column based on the index of a child element.
我知道有一种数学方法可以做到这一点,我宁愿不使用普通的网格.
I know there is a mathematical way of doing this and would rather not use a normal Grid.
如果有帮助,我可以使用以下方法获取行和列的总数:
If it helps, I can get the total number of rows and columns by using:
Math.Sqrt([*uniformgrid*].Children.Count)
推荐答案
抱歉,这是在 C# 中,但原则上您需要这样做
Sorry this is in C# but in principle you need to do
int rows = theGrid.Rows;
int columns = theGrid.Columns;
int index = theGrid.Children.IndexOf(childElement);
int row = index/columns; // divide
int column = index%columns; // modulus
在 VB.NET 中
dim rows as Integer = theGrid.Rows
dim columns as Integer = theGrid.Columns
dim index as Integer = theGrid.Children.IndexOf(childElement)
dim row as integer = index \ columns
dim column as integer = index mod columns
这篇关于根据 WPF 中的索引在 UniformGrid 中查找子行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文