Best way to create an "OnContentChanged" event for event?
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.
"Make it exist,"
-- Arkaen Solutions
-- Arkaen Solutions
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Best way to create an "OnContentChanged" event for event?
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?
You can listen to changes happening to the ContentControl.Content property and then execute any action (InvokeCommandAction, ControlStoryboardAction, ChangePropertyAction...).
Could that work for you?
Re: Best way to create an "OnContentChanged" event for event?
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.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?
"Make it exist,"
-- Arkaen Solutions
-- Arkaen Solutions
Who is online
Users browsing this forum: No registered users and 7 guests