I have a class testviewModel which has implemented INotifychanged event and all its proeprties.
public class testViewModel:INotifychanged
{
public string ServiceTag
{
get { return _serviceTag; }
set { _serviceTag = value;
PropertChanged("ServiceTag");}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void PropertChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
And I have a datagrid which is binding to the properties of the viewModel.
On the window load Im binding using like this:
DataGrid.ItemsSource = ObservableCollection;
And it shows the records in the datagrid with the properties of teh testViewModel.
But when I fire the delete event, it deletes from the database but it doesn’t update the UI or refresh datagrid.
I am calling DataGrid.Items.Refresh();
Do I have to specifically remove from the observable collection?
Is there anything I have to do in xaml?
Yes, because that is what the
DataGridis bound to. It could not possibly know that you have deleted a record from the database. You could also change out the collection completely as long as the property itself raises aPropertyChangedevent, but you should simply remove the item from the collection.