C# 在Windows应用商店应用程序中将数据项从一个页面添加到另一个页面?
我正在使用WindowsStore GridApp模板在VS2012 c/xaml中创建windows应用商店应用程序。 我正在使用此模板的组和项目页面 在“组”页面中,我显示了一个房间列表,其中的数据源是RoomObjectsC# 在Windows应用商店应用程序中将数据项从一个页面添加到另一个页面?,c#,wpf,xaml,windows-8,windows-store-apps,C#,Wpf,Xaml,Windows 8,Windows Store Apps,我正在使用WindowsStore GridApp模板在VS2012 c/xaml中创建windows应用商店应用程序。 我正在使用此模板的组和项目页面 在“组”页面中,我显示了一个房间列表,其中的数据源是RoomObjects public class RoomsObject : LivingDataCommon { public RoomsObject() : base(String.Empty, String.Empty) { }
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; }
}
}
当我在“项目”页面中选择一个参与者时,我的appbar会出现,我需要在我的pinButton上允许该参与者也显示在Home.xaml中
我假设我应该创建一个空的ObservableCollection并向其中添加选定的项,然后将该集合用作Home.xaml的数据源,但我是c新手,我无法让它工作
请提供任何建议、代码或其他方法来执行此操作?嗯。。只是给你一些建议。我可能会为此创建一个全局静态类,您可以从整个应用程序公共静态类PinnedActors访问该类。在这个类中,您有静态ObservableCollection。我使用这个类公共类AllActors:LivingDataCommon{public AllActors:baseString.Empty,String.Empty{}public AllActors字符串ID,字符串标题:baseID,title{}private ObservableCollection _AllActors=new ObservableCollection;public ObservableCollection AllActors{get{return this._AllActors;}}}}}}这是我的按钮代码,但它没有添加任何私有无效按钮_1对象发送方,TappedRoutedEventArgs e{AllActors m=new AllActors;m.AllActors.AddActorObjectItemGridView.SelectedItem;}如果你不告诉我什么是不起作用的,我就帮不了你。为什么不指定一个集合{};allActors的方法?无论如何,你应该接近一个解决方案。没有例外,只要我点击按钮,它什么也不做。我想我需要建立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); }
}
}