Best way to create an "OnContentChanged" event for event?
Posted: 16 Jan 2026, 04:12
I was curious what the recommended approach would be to creating an "OnContentChanged" event for content controls to listen to navigation events and trigger things like transition animations (or is there a simpler way?) ...
ContentControl in WPF doesn't offer this out of the box, and I've considered things like inheriting ContentControl to produce "AnimatedContentControl" or something like that. The way things are structured is that I have a "root" Page with a ContentControl that holds sub-menu sections with {Binding ActiveViewModel} and the navigation system swaps those out with caching/recycling (for those marked with a C++ enum trait like is_recycled_vm<T> or C# generic constraints -- those without the trait/constraints get new()'ed up and recreated when navigated to). The view model could potentially trigger events in the view when the OnNavigation delegate/event is fired. But I need some way to cleanly hook into this in the view in XAML for a data trigger or something. I added the event boilerplate and reflection to the root page view but haven't decided how I want to wire this up to capture it.
ContentControl in WPF doesn't offer this out of the box, and I've considered things like inheriting ContentControl to produce "AnimatedContentControl" or something like that. The way things are structured is that I have a "root" Page with a ContentControl that holds sub-menu sections with {Binding ActiveViewModel} and the navigation system swaps those out with caching/recycling (for those marked with a C++ enum trait like is_recycled_vm<T> or C# generic constraints -- those without the trait/constraints get new()'ed up and recreated when navigated to). The view model could potentially trigger events in the view when the OnNavigation delegate/event is fired. But I need some way to cleanly hook into this in the view in XAML for a data trigger or something. I added the event boilerplate and reflection to the root page view but haven't decided how I want to wire this up to capture it.