当我点击第1页的按钮时,我想将ObversableCollecion temp从page1传递到page2。但是我不想使用MVVM,只是简单。我的代码如下:
第1页:
public ObservableCollection<Staff> Staff_Collection { get; set; }
private void button_click1(object sender, RoutedEventArgs e)
{
Page1 page1= new Page1();
page1.Staff_Show = Staff_Collection;
this.NavigationService.Navigate(page1);}
第2页:
public ObservableCollection<Staff> Staff_Show = new ObservableCollection<Staff>();
public TaxBefore_Sum()
{
InitializeComponent();
DataContext = this;
Staff_Show = new ObservableCollection<Staff>();
}
但它没有用。
答案 0 :(得分:0)
var whateverPage = new WhateverPage(whateverDataYouWantToPass);
this.NavigationService.Navigate(whateverPage);
请确保WhateverPage
的构造函数(您导航到的页面)已超载,以接受您传递给它的项目,如下所示:
public WhateverPage(WhateverData data)
{
// code here
}
因此,在您的情况下,如果您导航到名为Page2
的页面,那么您将在该页面中创建一个构造函数,如下所示:
public Page2(ObservableCollection<Staff> staff)
{
// Now you have staff in Page2. You can assign it to a property or field
}