I have a datagrid that is bound to an observable collection, when I update the items in the observable collection the data grid is not updating. I know that I notify won't fire since i'm not changing the collection just the properties, so I am trying to set the item source to null and the rebinding it after it checks for updates, but this is not working. Also I have tried items.refresh to no avail. The only thing I have found that works is by renavigating back to the PendingChanges page.
To get an idea of how this works. I have a window that has a page in it, and at the bottom is a window that is framed in, when you click a button it navigates to the window that contains the datagrid (pending changes)
Class and Page that contains the datagrid
public PendingChanges(page blahh)
{
InitializeComponent();
Datagrid.ItemsSource = obvs_collection;
}
public string GetPendingChanges()
{
PopulatePendingChanges();
return NumberOfItemsPending + " items checked out";
}
private void PopulateCollection()
{
//obvs_collection.Clear(); this doesn't work
//Datagrid.ItemsSource = null this doesn't work
foreach (var path in localPath)
{
obvs_collection.Add(new PendingItem()
{
ID = blah.Replace("\\",""),
Path = path.ToString()
});
}
}
Class/Page that frames in the page with the data grid
private void CheckChanges()
{
_pendingChangesPage = new PendingChanges(blah);
PendingChangesTb.Text = _pendingChangesPage.GetPendingChanges();
}
更新任何数据源以反映其更改时,需要使用其.Refersh()函数刷新网格。
dataGrid.Items.Refresh();
I'm thinking you would probably want just a single instance instead of creating a new one everytime you check for changes.
Try this:
PendingChanges _pendingChangesPage;
public PendingChanges(page blahh)
{
InitializeComponent();
Datagrid.ItemsSource = obvs_collection;
_pendingChangesPage = new PendingChanges(blah);
}
private void CheckChanges()
{
PendingChangesTb.Text = _pendingChangesPage.GetPendingChanges();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.