在Windows Phone 7中创建图像数组

本文关键字:创建 图像 数组 Windows Phone | 更新日期: 2023-09-27 18:18:15

我正在尝试在c#中为windows phone 7创建一个可见的图像数组。我:

    Image[] stone = new Image[100];
    public Game() //constructor
    {
        InitializeComponent();
        stone[0] = new Image();
        BitmapImage bi = new BitmapImage();
        bi.SetSource(Application.GetResourceStream(new Uri(@"notselected.png", UriKind.Relative)).Stream);
        stone[0].Source = bi;
        stone[0].Width = 200;
        stone[0].Height = 200;
        stone[0].Opacity = 1.0;
    }

编译,但不显示图像。我该怎么办?

在Windows Phone 7中创建图像数组

您必须将图像添加到页面中的控件,例如grid或stackpanel:

 MyGrid.Children.Add(stone[0]);

内存中有一堆图像,但这并不是魔法;运行时不只是假设你想要显示这些图像,然后还假设如何显示它们。

您必须将图像添加到显示其子控件的某个控件中。你可以使用一个网格,一个ListView填充一个ImageList,等等。