I have a menu button that opens a window when clicked.
I want to change it’s color when it is clicked and revert when the window is closed.
I thought to use trigger to change it’s color when clicked but how can i know when the window was closed to change the color back?
i need it in mvvm way so i prefer not using code behind
One of the patterns that go hand in hand with a view model is the Event Aggregator. The basic gist is that you create a message bus that allows interested objects to subscribe to specific events that other objects might fire without requiring a direct coupling between the two.
Your main view model might subscribe to a WindowClosed event (that provides an identifier for determining which specific window has closed). When your dialog has closed, its view model would be responsible for firing the event.
When your view model receives the event it would then update the property, that your menu item’s trigger is bound to.