Question

I have a custom treeview inside a user control. It exposes a dependency property that represents the currently selected treeviewitem. In the same window i have another user control that should change content of it's controls when the selected item changes. I need to do this changes from code behind. How do i fire up an event in the second user control when the selected item changes in the first one?

Was it helpful?

Solution

As the Dependency property whose change you want to be notified about is one created by yourself, why don't you register a PropertyChangedCallback for that property in your user control? This way, you can add a SelectedItemChanged event to the control and raise it from the PropertyChangedCallback code.

Any object that needs to know when the selectedItem has changed just has to listen to this new event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top