在Windows Store Apps中从一个页面添加数据项到另一个页面
本文关键字:一个 添加 数据项 另一个 Apps Store Windows | 更新日期: 2023-09-27 18:19:22
我正在使用WindowsStore GridApp模板在VS2012 c#/xaml中创建windows store应用程序。我使用的是这个模板的组和项页面。
在组页面中,我正在显示房间列表-这是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; }
}
}
在项目页面中,我显示了每个房间的演员列表-数据源是actor对象
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); }
}
}
当我选择一个演员在项目页面我的appbar出现,我需要在我的pinButton上允许该演员显示在家里。
我假设我应该创建一个空的ObservableCollection并向其添加选定的项目,然后使用该集合作为Home的数据源。xaml,但我是c#的新手,我不能让它工作…
请给出任何建议,代码,或一些不同的方法来做到这一点?
嗯…只是给你们一些输入。我可能会为此创建一个"全局"静态类,你可以从你的整个应用程序(公共静态类PinnedActors)访问。在这个类中,你有你的静态ObservableCollection.