0

我正在使用 WindowsStore GridApp 模板在 VS2012 c#/xaml 中创建 Windows 商店应用程序。我正在使用此模板具有的组和项目页面。

在组页面中,我正在显示房间列表 - 数据源是 RoomObjects

 public class RoomsObject : LivingDataCommon
{
    public RoomsObject()
        : base(String.Empty, String.Empty)
    {

    }



    public RoomsObject(String ID, String title)
        : base(ID, title)
    { }

    //adds Actors to collection of a Room, will be used for Rooms pages
    private ObservableCollection<ActorsObject> _actors = new ObservableCollection<ActorsObject>();
    public ObservableCollection<ActorsObject> Actors
    {
        get { return this._actors; }
    }





}

在 Item 页面中,我显示了每个 Room 拥有的 Actor 列表 - 数据源是 ActorsObjects

public class ActorsObject : LivingDataCommon
{
       public ActorsObject()
        : base(String.Empty, String.Empty)
    {
    }

    public ActorsObject(String ID, String title, Boolean homepage,String function, RoomsObject room, double currentValue, ActorsType type, AllActors allactors)
        : base(ID, title)
    {
        this._function = function;
        this._room = room;
        this._currentValue = currentValue;
        this._type = type;
        this._homepage = homepage;
        this._all = allactors;
    }
    //set home page appearance
    private Boolean _homepage = false;
    public static Boolean Homepage = false;




    //sets value of an actor
    private double _currentValue;
    public double CurrentValue
    {
        get { return this._currentValue; }
        set { this.SetProperty(ref this._currentValue, value); }
    }

    //sets and gets function code
    private string _function = string.Empty;
    public string Function
    {
        get { return this._function; }
        set { this.SetProperty(ref this._function, value); }
    }

    //gets room properity
    private RoomsObject _room;
    public RoomsObject Room
    {
        get { return this._room; }
        set { this.SetProperty(ref this._room, value); }
    }

    private ActorsType _type;
    public ActorsType Type
    {
        get { return this._type; }
        set { this.SetProperty(ref this._type, value); }
    }

    private AllActors _all;
    public AllActors All
    {
        get { return this._all; }
        set { this.SetProperty(ref this._all, value); }
    }
}

当我在 Items 页面中选择一个 Actor 时,我的 appbar 会出现,我需要在我的 pinButton 上允许该 Actor 也显示在 Home.xaml 中。

我假设我应该创建一个空的 ObservableCollection 并向其中添加选定的项目,然后将该集合用作 Home.xaml 的数据源,但我是 c# 的新手,我无法让它工作..

请任何建议,代码或一些不同的方法来做到这一点?

4

1 回答 1

0

嗯..只是给你一些输入。我可能会为此创建一个“全局”静态类,您可以从整个应用程序中访问它(公共静态类 PinnedActors)。在这个类中,你有你的静态 ObservableCollection。

于 2013-06-23T20:37:08.777 回答