我有一个3x3的网格,其中包含9个图像。是否有可能将其转换为Images数组[] [],或只是循环通过我的网格的每个单元格?网格到数组[] []或在每个单元中查找项目
重点是在我的每个9个细胞中都有一个图像。我只想知道哪个图像在特定的单元格中。
编辑
这里是我的XAML代码,但它只是在我的布局创建细胞
<Grid x:Name="Map">
<!-- Row and coulmns definition -->
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="120"/>
<RowDefinition Height="120"/>
<RowDefinition Height="120"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="128*" />
</Grid.ColumnDefinitions>
<!-- Canvas & Components -->
<Canvas
x:Name="MyCanvas"
Background="Azure"
Grid.ColumnSpan="3"
Grid.RowSpan="3">
</Canvas>
<Button Background="Chocolate" Content="Spin" Name="SpinButton" Grid.Row="3" Grid.Column="3" Click="SpinButton_Click" Grid.ColumnSpan="2" Margin="15,36,12,12" />
</Grid>
我主要是做everyting在C#代码behid。 我使用Storyboard类动画图像,最后将我的9个图像设置为特定位置(每个图像都在9个单元中)。 我得到您的代码也尝试将Image更改为FrameworkElement,但无论如何它只是看到Canvas Element。也许有一个选项可以从特定坐标中获取元素?
添加图像C#:
public List<Image> SetImages(String order)
{
List<Image> line = new List<Image>();
for (int i = 0; i < imagesQty; i++)
{
Image img1 = new Image();
img1.Source = ananasImage;
img1.Stretch = Stretch.Fill;
img1.Width = 200;
img1.Height = 120;
if (order.Equals("left"))
{
line.Add(img1);
Canvas.SetTop(img1, -200);
Canvas.SetLeft(img1, 0);
MyCanvas.Children.Add(img1);
}
else if (order.Equals("middle"))
{
line.Add(img1);
Canvas.SetTop(img1, -200);
Canvas.SetLeft(img1, 180);
MyCanvas.Children.Add(img1);
}
else if (order.Equals("right"))
{
line.Add(img1);
Canvas.SetTop(img1, -200);
Canvas.SetLeft(img1, 360);
MyCanvas.Children.Add(img1);
}
}
return line;
}
您现在可以提供代码示例吗? – rivanov
只有行&&列定义。故事板将图像放入其中。 – miechooy