Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image windows phone 8:用户控件中的图像:奇怪的行为_Image_User Controls_Windows Phone 8 - Fatal编程技术网

Image windows phone 8:用户控件中的图像:奇怪的行为

Image windows phone 8:用户控件中的图像:奇怪的行为,image,user-controls,windows-phone-8,Image,User Controls,Windows Phone 8,我制作了一个由许多图像组成的用户控件。但是这些图像没有显示出来 如果我导航到其他一些页面,这些页面直接包含xaml中的图像(所有图像与源文件共享相同的png),那么我将返回,usercontrol中的图像将显示出来 为什么??关于缓存 谢谢 public partial class PatternView : UserControl { List<List<Cube>> pattern; ObservableCollection<Observable

我制作了一个由许多图像组成的用户控件。但是这些图像没有显示出来

如果我导航到其他一些页面,这些页面直接包含xaml中的图像(所有图像与源文件共享相同的png),那么我将返回,usercontrol中的图像将显示出来

为什么??关于缓存

谢谢

public partial class PatternView : UserControl
{
    List<List<Cube>> pattern;
    ObservableCollection<ObservableCollection<Image>> image;
    public PatternView()
    {
        InitializeComponent();
    }
    public void Init(int row, int col)
    {
        LayoutRoot.RowDefinitions.Clear();
        LayoutRoot.ColumnDefinitions.Clear();
        List<List<Cube>> a=new List<List<Cube>> ();
        ObservableCollection<ObservableCollection<Image>> b = new ObservableCollection<ObservableCollection<Image>>();
        for (int i = 0; i < row; i++)
        {
            LayoutRoot.RowDefinitions.Add(new RowDefinition());
            a.Add(new List<Cube>());
            b.Add(new ObservableCollection<Image>());
        }
        for (int i = 0; i < col; i++)
        {
            LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
        }
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                a[i].Add(new StoneCube());
                Image img = new Image() 
                { Source = a[i][j].icon };

                img.Source = new BitmapImage(new Uri("Resources/CubeImage/Stone.png", UriKind.Relative));
                b[i].Add(img);

                LayoutRoot.Children.Add(img);
                Grid.SetRow(img, i);
                Grid.SetColumn(img, j);
            }
        }
        pattern = a;
        image = b;
    }
public部分类模式视图:UserControl
{
列表模式;
可观测采集图像;
公共模式视图()
{
初始化组件();
}
公共void Init(整数行,整数列)
{
LayoutRoot.RowDefinitions.Clear();
LayoutRoot.ColumnDefinitions.Clear();
列表a=新列表();
ObservableCollection b=新的ObservableCollection();
对于(int i=0;i
“图像”中的所有元素都不会显示。但是,如果我转到另一个页面,该页面只显示同一资源的图像,然后返回,则一切正常

public class Cube
{
    public string name { get; set; }
    public int type;
    public BitmapImage icon { get; protected set; }
    protected int rowSpan;
    protected int colSpan;

    public Cube() 
    {
        name = "basic Cube";
    }
    public Cube(int type)
    {
        name = "basic Cube";
        this.type = type;
    }
}
public class NullCube : Cube
{
    public NullCube() : base()
    {
        name = "null";
        icon = ProgramData.CubeImages["Null"];
    }
}
public class UsedCube : Cube
{
    public UsedCube() : base()
    {
        name = "used";
        icon = ProgramData.CubeImages["Null"];
    }
}
public class StoneCube : Cube
{
    public StoneCube() : base()
    {
        name = "stone";
        icon = ProgramData.CubeImages["Stone"];
    }
}
public class AmmoCube : Cube
{
    public AmmoCube() : base()
    {
        name = "ammo";
        icon = ProgramData.CubeImages["Ammo"];
    }
}

static class ProgramData
{
    public static Dictionary<string,BitmapImage> CubeImages = new Dictionary<string, BitmapImage>();
    public static ObservableCollection<Cube> ChooseCubeBar { get; set; }


    static ProgramData()
    {
        CubeImages.Add("Stone", new BitmapImage(new Uri("Resources/CubeImage/Stone.png", UriKind.Relative)));
        CubeImages.Add("Null", new BitmapImage(new Uri("Resources/CubeImage/Null.png", UriKind.Relative)));
        CubeImages.Add("Ammo", new BitmapImage(new Uri("Resources/CubeImage/Ammo.png", UriKind.Relative)));
        CubeImages.Add("Cannon", new BitmapImage(new Uri("Resources/CubeImage/Cannon.png", UriKind.Relative)));
    }
公共类多维数据集
{
公共字符串名称{get;set;}
公共int类型;
公共位图图像图标{get;protected set;}
受保护的整数行跨度;
受保护的int colSpan;
公共多维数据集()
{
name=“基本立方体”;
}
公共多维数据集(int类型)
{
name=“基本立方体”;
this.type=type;
}
}
公共类NullCube:Cube
{
公共NullCube():base()
{
name=“null”;
icon=ProgramData.CubeImages[“Null”];
}
}
使用的公共类多维数据集:多维数据集
{
公用多维数据集():base()
{
name=“已使用”;
icon=ProgramData.CubeImages[“Null”];
}
}
公共级石立方:立方体
{
公共石立方():base()
{
name=“stone”;
icon=ProgramData.CubeImages[“Stone”];
}
}
公共类多维数据集:多维数据集
{
公共多维数据集():base()
{
name=“弹药”;
icon=ProgramData.CubeImages[“Ammo”];
}
}
静态类程序数据
{
public static Dictionary CubeImages=new Dictionary();
publicstaticobserveCollection选择subebar{get;set;}
静态编程数据()
{
添加(“Stone”,新位图图像(新Uri(“Resources/CubeImage/Stone.png”,UriKind.Relative));
Add(“Null”,新位图图像(新Uri(“Resources/CubeImage/Null.png”,UriKind.Relative));
Add(“Ammo”,新位图图像(新Uri(“Resources/CubeImage/Ammo.png”,UriKind.Relative));
Add(“Cannon”,新位图图像(新Uri(“Resources/CubeImage/Cannon.png”,UriKind.Relative));
}

你能提供一个代码示例吗?你说的“由许多图像组成的用户控件”是什么意思?发布一些代码,显示哪些控件没有正确显示图像,以及它们是如何初始化/创建/绑定的。如果我将BitmapCreateOption更改为BitmapCreateOption。无,已解决,但这会影响性能吗?