InvokeActionCommand never called when using EventTriggerBehavior with Unloaded event name #18333
Unanswered
rprimora-pricer
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As per title, I am using
EventTriggerBehavior
withInvokeCommandAction
. I am adding one behavior for bothLoaded
andUnloaded
events.Loaded
is working fine. However, theUnloaded
is not. It never gets called.I have tried using
DetachedFromVisualTree
and I have also tried usingRoutedEventTriggerBehavior
but to no avail.Normally I have a
Load
andUnload
commands defined in every view model. This is all hooked up as follows:The only thing that comes as close to the unload is the following code:
This is the project that reproduces this - UnloadedIssue.zip
When you run the project you will get a simple Window that has two buttons on the left side and content on the right. Switch the content with buttons and observer the Debug output. You should get corresponding feedback for each event. Such as:
FirstView LOADED
SecondView LOADED
If I click on First view button and then click on the Second view button I would expect the output to be as follows:
FirstView LOADED
FirstView UNLOADED
SecondView LOADED
Now comes the actual strangest part of all. This is in my own project which I cannot share here. Furthermore, I could not reproduce this behavior in the project I shared with you.
The strangest thing is that initial implementation, the one I expect to work, works on some views. This view that works also implements the
Loaded
andUnloaded
events. As in, I have subscribed to them. This means that when the view actually loads, first the subscribed method will be called (e.g. UserControl_Loaded) after which the behavior will call my command. However, if I remove subscription toUnloaded
event, behavior stops working. As I've said, I can't reproduce this though, but maybe it means something to someone.Beta Was this translation helpful? Give feedback.
All reactions