【发布时间】:2015-06-04 16:02:05
【问题描述】:
我有一个 3x3 的网格,其中包含 9 个图像。是否可以将其转换为图像数组[][],或者只是循环遍历我网格的每个单元格?
重点是在我的 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>
我大部分时间都隐藏在 C# 代码中。 我正在使用 Storyboard 类为图像设置动画,最后将我的 9 个图像设置到特定位置(每个图像都在 9 个单元格中)。 我得到您的代码也尝试将 Image 更改为 FrameworkElement,但无论如何它只看到 Canvas 元素。也许可以选择从特定坐标中获取元素?
添加图像 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;
}
【问题讨论】:
-
您能提供一个现在的代码示例吗?
-
只有行 && 列定义。故事板将图像放入其中。
标签: c# windows-phone-7