在C#
WPF
我有一个窗口,它使用this.WorkingFrame.Navigate(Page1);
第 1 页上的“现在”托管一个页面,我有一个listview
. 在第 1 页上,您可以双击listview
打开新窗口 (Page2) 中的项目来编辑该项目。一旦项目被编辑,它被保存到datacontext
. 现在我遇到的问题是,一旦 Page2 关闭,listview
就不会更新。基本上我必须离开页面并返回它以显示更改。有没有办法从 Page2 刷新 Page1 以显示所做的更改?这是我的代码
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//initiates the method to load data into the list view
LoadLV();
}
//Loads data into the list view object
public void LoadLV()
{
auroraDataEntities = new AuroraDataEntities();
Data data = new Data();
ObjectQuery<Inventory> inventories = auroraDataEntities.Inventories;
//Returns only objects with a quantity greater than 0, so it won't show anything you are out of
var fillList = from q in inventories
where q.Qty > 0
select q;
ingListLV.ItemsSource = fillList.ToList();
}
//Method to open what I want to be the child window basically a popup Dialog box
private void Open_Page2(object sender, RoutedEventArgs e)
{
Page2 openPage2 = new Page2();
openPage2.Show();
}
}
//This is the code for Page 2
public partial class Page2 : Window
{
public Page2()
{
InitializeComponent();
//ADDED a reference to Page1 in the constructor
Page1 page1;
}
//Method when i click the close button on the page
private void Close_Button(object sender, RoutedEventArgs e)
{
//In here is the code that I want to use to refresh the listview on page 1
//ADDED the call to the public method LoadLV on page 1
page1.LoadLV()
}
}