2022-02-27

Drop-down not updating when calling RaisePropertyChanged (Prism, BindableBase, WPF)

I want to update the data on drop-down in a view from my view-model. The data is updated in some objects in my model. I understood that the INotifyPropertyChanged interface only works on view-model level. But I thought when the view-model subscribe to an event that I can update my view by raising the RaisePropertyChanged for the object in the view-model which needs to be updated.

I call the UpdateConfiguration() which triggers to fetch the new data. Becacuse the function PutSetupWorkspaceConfiguration() is time consuming it returns the the first data and then compute the rest in the background. After its done its rasing the IsChanged event which works. So the method OnListChanged() gets called but then the gui does not update.

What am I doing wrong since the event and the getter gets called?

/*viewmodel*/
private SetupWorkspaceConfiguration setupWorkspaceConfiguration;

public ObservableCollection<TestingModel> TestingModels
{
   get => setupWorkspaceConfiguration?.TestingModels; //The event calls getter but the gui does not update the data
}

public async Task UpdateConfiguration(int? projectId)
{
   setupWorkspaceConfiguration = await Task.Run(async () => await setupWorkspaceConfigurationStore.PutSetupWorkspaceConfiguration(projectId));            
   setupWorkspaceConfiguration.IsChanged -= OnListChanged;
   setupWorkspaceConfiguration.IsChanged += OnListChanged;
}
private void OnListChanged(object? sender, System.EventArgs e)
{
    RaisePropertyChanged(nameof(TestingModels));
}

EDIT: The elements in the list setupWorkspaceConfiguration.TestingModels will updated. This is working fine. But when i add new elements to the list this will not be shown in the dropdown.



No comments:

Post a Comment