User avatar
arkaen
Topic Author
Posts: 20
Joined: 08 Apr 2023, 01:23
Location: Baton Rouge, LA
Contact:

Best way to create an "OnContentChanged" event for event?

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.
"Make it exist,"
-- Arkaen Solutions
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Best way to create an "OnContentChanged" event for event?

16 Jan 2026, 11:36

Have you tried using the PropertyChangedTrigger?
You can listen to changes happening to the ContentControl.Content property and then execute any action (InvokeCommandAction, ControlStoryboardAction, ChangePropertyAction...).
Could that work for you?
 
User avatar
arkaen
Topic Author
Posts: 20
Joined: 08 Apr 2023, 01:23
Location: Baton Rouge, LA
Contact:

Re: Best way to create an "OnContentChanged" event for event?

16 Jan 2026, 22:08

Have you tried using the PropertyChangedTrigger?
You can listen to changes happening to the ContentControl.Content property and then execute any action (InvokeCommandAction, ControlStoryboardAction, ChangePropertyAction...).
Could that work for you?
Probably, but the first time I tried that it seemed like it only fired the first time I load the view and set it or on shutdown. But you know how blind and dumb I get if I stay up too late, so it's entirely possible I overlooked something super obvious, haha. I think I captured all the property changed events and looked at the name, which I didn't care for ... I think it passes a Noesis::Symbol instance and I prefer to avoid string comparison operations.
"Make it exist,"
-- Arkaen Solutions

Who is online

Users browsing this forum: No registered users and 7 guests