简体   繁体   English

如何在不使用MVVM的情况下将ObservableCollection从一个page1传递到page2

[英]how to pass ObservableCollection from one page1 to page2 without use MVVM

I want to pass ObversableCollecion temp from page1 to page2 ,when I click the button in page1.But I don't wan't to use MVVM,just be simnple.My code are as follows: 当我单击page1中的按钮时,我想将ObversableCollecion临时从page1传递到page2。但是我不想使用MVVM,请简单地说。我的代码如下:
page1: 第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);}

page2: 第2页:

public ObservableCollection<Staff> Staff_Show = new ObservableCollection<Staff>();
    public TaxBefore_Sum()
    {
        InitializeComponent();
        DataContext = this;
        Staff_Show = new ObservableCollection<Staff>();
    }

but it doesn't work. 但这不起作用。

var whateverPage = new WhateverPage(whateverDataYouWantToPass);
this.NavigationService.Navigate(whateverPage);

Just make sure, the constructor for WhateverPage (the page you are navigating to) is overloaded to accept the item you are passing into it like this: 只需确保, WhateverPage (导航到的页面)的构造函数已超载,以接受您要传递给它的项目,如下所示:

public WhateverPage(WhateverData data)
{
    // code here
}

So in your case, if you are navigating to a page called Page2 , then you will create a constructor in that page like this: 因此,在您的情况下,如果导航到名为Page2的页面,则将在该页面中创建一个构造函数,如下所示:

public Page2(ObservableCollection<Staff> staff)
{
    // Now you have staff in Page2. You can assign it to a property or field
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用sessioon将列表框项目从page1传递到page2 - Pass listbox items from page1 to page2 using sessioon 将ListView选择从Page2传输到Page1 - Transferring ListView selection from Page2 to Page1 WPF 在Page1中添加文本,导航到Page2,然后在Page2中查看 - WPF Add Text in Page1, Navigate to Page2, and See it in Page2 将Page1文本传递到第2页WPF MVVM - Passing Page1 Text to Page 2 WPF MVVM 如何单击按钮并使用WPF在Page2中使用“返回”按钮选择在Page1中的组合框中选择的上一个值 - How to click on button and select previous value selected in combo box in Page1 using go back button in Page2 using WPF 如何将ObservableCollection从ViewModelA传递到MVVM中的ViewModelB - How to pass ObservableCollection from ViewModelA to ViewModelB in MVVM 使用MVVM在WPF中将字段从一页传递到另一页 - Pass Field from one page to another page in WPF using MVVM 是否有TAB控件,以及如何通过单击按钮打开page2? - Is there TAB control and how to open page2 from button click? 如何在没有 mvvm light 的情况下将参数传递给导航页面的视图模型 - How to pass a parameter to the viewmodel of the navigated page without mvvm light 如何使用正确的 MVVM 在不同的内容页面中传递数据 Xamarin - How to use proper MVVM to pass data in different content page Xamarin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM