✅ What is OnPropertyChanged actually doing here?

This is an MVVM question for WPF on .NET Framework (not core).

The program im inquerying about is a program I made that uses a combo box to switch between two different views on the main window.

I have a view that uses a combo box to hold 2 strings that when selected will change the contentcontrol to display another view. The combobox gets its list from an ObservableCollection and the selecteditem is bound to a property. On the selecteditem property, I call my OnPropertyChanged method to notify the UI that the selecteditem has changed, and also update contentcontrol property (which calls another OnPropertyChanged to notify the UI that the contentcontrol has switched views).

I don’t understand what the purpose of the OnPropertyChanged call is on the selecteditem property because both the combobox and contentcontrol seem to update when UpdateCurrentView accesses the CurrentView property and CurrentView does its own OnPropertyChanged call. I would only expect the ContentControl to change not the selecteditem string. Why and how does the UI successfully update both the SelectedItem (what the combobox says) and the ContentControl (the different views) when I remove the "OnPropertyChanged" for the SelectedView property ?

MainWindow.xaml: https://pastebin.com/raw/YmVwuQTb
MainWindowViewModel.cs: https://pastebin.com/raw/FNQyNyWH
Was this page helpful?