【发布时间】:2013-08-12 10:01:56
【问题描述】:
在C# WPF 我有一个窗口使用this.WorkingFrame.Navigate(Page1); 托管页面
现在在第 1 页我有一个listview。在第 1 页上,您可以双击 listview 中的项目以打开一个新窗口(第 2 页)以编辑该项目。一旦项目被编辑,它就会被保存到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()
}
}
【问题讨论】:
-
如果你正确使用它,你应该考虑使用一个可观察的集合,你的 ui 将自动反映变化。即使在对话框关闭之前,您的更改也会反映在第 1 页中
标签: c# wpf entity-framework