all, I am working on a WPF application . In which I am using Data grid and it is bound to an Icollection customerCollection . I am using MVVM.
I have a button to add a new customer that shows a Dialog box by clicking it. through that Dialogbox I save data into my SQL server Database. Everything is ok but when Dialog box closes( CloseAction(); ). Datagrid does not update. What should I do? When I go back to any other menu item and click back on customer, Datagrid is updated, while I am calling the same function in constructor and in command execution. Images are attached for reference Any solution will be truly appreciated.
public CustomerViewModel()
{
ShowNewCustomerWindowCommand = new ViewModelCommand(ExecuteShowNewCustomerWindowCommand);
SearchCustomerCommand = new ViewModelCommand(ExecuteSearchCustomerCommand);
GetData();
}
protected void GetData()
{
customer = new ObservableCollection<CustomerModel>();
customer = customerRepository.GetByAll();
customerCollection = CollectionViewSource.GetDefaultView(customer);
customerCollection.Filter = FilterByName;
customerCollection.Refresh();
RaiseProperChanged();
}
private void ExecuteShowNewCustomerWindowCommand(object obj)
{
var addNewCustomer = new AddNewCustomer();
addNewCustomer.ShowDialog();
}
private void ExecuteSaveCustomerCommand(object obj)
{
customerModel.FirstName = FirstName;
customerModel.LastName = LastName;
customerModel.Contact = Contact;
customerModel.Address = Address;
customerRepository.Add(customerModel);
CloseAction();
GetData();
}