开发者

ObservableCollection and displaying its data question, Windows Phone 7

开发者 https://www.devze.com 2023-03-24 14:04 出处:网络
I am developing a part of my app where I need to take images I have in the phone (user downloads them with the application) and displaying them in a databound listbox. Let us call this Page1.

I am developing a part of my app where I need to take images I have in the phone (user downloads them with the application) and displaying them in a databound listbox. Let us call this Page1.

However, I want to be able to add to this collection when a user "favorites" an image from my RSS feed. Let us call this page 2.

So in essence, I want to combine Page1 items and Page2 items, and display them on Page1. I also want to be able to allow users to remove any of the images they like from being shown.

I am uncertain how to go about this. Do I create a separate class, and write all the items to a file in isolated storage?

mock code (since not on my app computer)

public class Imagelist : ObservableCollection<Images>
{
  public Imagelist() : base()
  {
    //add items from page1.
    //add items from page2.

    Add(new Images("Imagepath"));
    ...    
  }
}

... get/set the pathing, maybe by setting all the images into a key?

Not sure, but definitely could use some开发者_开发百科 insight.


Implementing the ImageList as a singleton should work. I've created a short example that adds strings instead of images.

void Main()
{
   var page1 = new Page1();
   var page2 = new Page2();

   foreach (var txt in ImageList.Instance)
   {
        Console.WriteLine (txt);
        // prints:
        // Instance created
        // page1
        // page2
   }
}

public class ImageList : ObservableCollection<string>
{
    private static ImageList _instance;
    public static ImageList Instance 
    { 
        get
        {
            if(_instance==null)
            {
                _instance = new ImageList();
                _instance.Add("Instance created");      
            }
            return _instance;
        }
    }

    private ImageList() 
    {
    }
}

public class Page1
{
    public Page1()
    {
        ImageList.Instance.Add("page1");
    }
}

public class Page2
{
    public Page2()
    {
        ImageList.Instance.Add("page2");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消