© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
31 replies
weef

✅ 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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Onpropertychanged
C#CC# / help
3y ago
❔ OnpropertyChanged WPF
C#CC# / help
3y ago
what is this code snippet doing?
C#CC# / help
4y ago