Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Such as get the object sure in Row one and Colum one.
Posted
Comments
Andy411 15-May-12 1:45am    
What is your goal? What do you want to achieve?
Did you take a look at the CurrentCell property?

The row and column properties for a WPF Grid are really attached dependency properties. So, certain static methods must be included inorder for those properties to be usable in XAML. You only need to loop through the children of the Grid to make sure you're going through the objects in the grid, and then you use those same methods to get the column and row of the object.

The following code is a simple example of how to do this. Please keep in mind that it runs under the assumption that each item has a column and row span of 1. In order to be on the safe side, you will also to have grab the spans of the objects' columns and rows, and do a little math to be sure an object overlaps the position you want.

C#
foreach (UIElement item in someGrid.Children)
{
   int column = Grid.GetColumn(item);
   int row = Grid.GetRow(item);

   if (column == expectedColumn && row == expectedRow)
   {
      // Do something.
   }
}
 
Share this answer
 
Comments
Elan.Cao 20-May-12 9:05am    
Thank you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900