I am working on a Windows Phone 7 application and I have a method
public void PaintButtons()
{
IList p1numlist = GenerateRandom();
IList p2numlist = GenerateRandom();
p1b1.Content = images.ElementAt((int)p1numlist[0]);
p1b2.Content = images.ElementAt((int)p1numlist[1]);
p1b3.Content = images.ElementAt((int)p1numlist[2]);
p2b1.Content = images.ElementAt((int)p2numlist[0]);
p2b2.Content = images.ElementAt((int)p2numlist[1]);
p2b3.Content = images.ElementAt((int)p2numlist[2]);
}
IList<Image> images = new List<Image>();
public Page1()
{
InitializeComponent();
LoadImages();
}
public void LoadImages()
{
Uri[] uri = new Uri[3];
uri[0] = new Uri("/BtnPics/Blue.png", UriKind.Relative);
uri[1] = new Uri("/BtnPics/Red.png", UriKind.Relative);
uri[2] = new Uri("/BtnPics/Yellow.png", UriKind.Relative);
foreach (Uri u in uri)
{
BitmapImage bmp = new BitmapImage(u);
images.Add(new Image() { Source = bmp });
}
}
I am stuck at this point, please help. The XAML content is as follows:
<grid height="800" name="LayoutRoot" width="478">
<grid.columndefinitions>
<columndefinition width="65*" />
<columndefinition width="413*" />
</grid.columndefinitions>
<Button Height="122" HorizontalAlignment="Left" Margin="-12,682,0,0" Name="p1b1" VerticalAlignment="Top" Width="170" Grid.ColumnSpan="2" TabIndex="3" />
<Button Height="122" HorizontalAlignment="Left" Margin="85,682,0,0" Name="p1b2" VerticalAlignment="Top" Width="170" Grid.Column="1" TabIndex="2" />
<Button Height="122" HorizontalAlignment="Left" Margin="248,682,0,0" Name="p1b3" VerticalAlignment="Top" Width="170" Grid.Column="1" TabIndex="1" />
<textblock height="68" horizontalalignment="Left" margin="60,618,0,0" name="player1textBlock" text="TextBlock" verticalalignment="Top" width="223" grid.column="1" />
<textblock height="68" horizontalalignment="Left" margin="61,116,0,0" name="player2textBlock" text="TextBlock" verticalalignment="Top" width="223" grid.column="1" />
<Image Height="220" HorizontalAlignment="Left" Margin="45,260,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="250" Grid.Column="1" />
<Button Grid.ColumnSpan="2" Height="122" HorizontalAlignment="Left" Margin="-12,-4,0,0" Name="p2b3" TabIndex="3" VerticalAlignment="Top" Width="170" />
<Button Grid.Column="1" Height="122" HorizontalAlignment="Right" Margin="0,-4,158,0" Name="p2b2" TabIndex="2" VerticalAlignment="Top" Width="170" />
<Button Grid.Column="1" Height="122" HorizontalAlignment="Left" Margin="248,-4,0,0" Name="p2b1" TabIndex="1" VerticalAlignment="Top" Width="170" />
</grid>
Can somebody help?