Finding a childs row and column in UniformGrid based on Index in WPF

前端 未结 1 1972
耶瑟儿~
耶瑟儿~ 2021-01-01 07:26

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 doin

相关标签:
1条回答
  • 2021-01-01 08:05

    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
    

    And in 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
    
    0 讨论(0)
提交回复
热议问题