![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Retrieving elements from a Grid in C#? Let's say I have a grid defined in XAML with 2 rows and 2 columns, with a button in each cell defined by the grid: <Grid x:Name="myGrid" > <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Button Grid.Row="0" Grid.Column="0" /> <Button Grid.Row="0" Grid.Column="1" /> <Button Grid.Row="1" Grid.Column="0" /> <Button Grid.Row="1" Grid.Column="1" /> </Grid> My question is, can I programmatically get a reference to a particular button object, given the row and column coordinates? For example, I'd love to be able to do this: Button buttonReference = myGrid.Children.get(0, 0); and have it return the button at 0,0 in the grid. While inspecting the API I can't seem to find something that would give me this desired functionality. System.Windows.Controls.Grid has a property Children (inherited from Panel) which returns a UIElementCollection. From there, the best you can do it get an Enumerator and loop through the children. There must be a way to pick out a single one, right? I'm going for performance as I will be updating the content of each grid child quite frequently, and I simply can't afford to enumerate the entire Children collection each time. Anyone found anything that may help? Regards, Jason |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Adobe Photoshop Elements 6 & Adobe Premiere Elements 4 | Vista music pictures video | |||
| Can't delete elements in folder Recent elements | Vista General | |||
| Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits | Vista General | |||