I have a 10x10 grid filled with buttons, textboxes, and images, each one just spans to it's single cell and they don't mix together never, I want to reference a certain object in a cell and change one of it's properties, for example, change the content of the button in cell 1,3 (rows,cols).
Here's a short example of my XAML:
<Grid x:Name="Minas" Margin="-2,115,3,33" Width="450" Height="450" MaxHeight="450" MaxWidth="450" MinWidth="450" MinHeight="450" d:IsLocked="True">
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
<Column开发者_StackOverflow中文版Definition Width="10*"/>
</Grid.ColumnDefinitions>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Padding="0" Click="descubrirMina" Background="#00E53E3E" />
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="1" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="3" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="2" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="4" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="5" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="6" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="8" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="9" Click="descubrirMina"/>
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Column="7" Click="descubrirMina"/>
Thx.
Give them proper names and then you can refer to them in code.
startButtonIn1row3col.Content = "start";
BTW Don't you think that 10x10 Grid is not too much for a phone screen?
I found the answer myself, for the ones that could want to know how do I resolved this issue was just decalring a grid with XAML with the column and row definitions required, next I created a class inherited from Button that contained the X and Y properties I needed, then I just created an array of this objects and programatically defined the properties (Size, span, etc) I needed and positionated them with: myGrid.Children.Add(the object) and then simply changed where in the grid I wanted them to display, so whenever I needed to acces or change a property for this "buttons" I just accessed to my array and voila!
精彩评论