I've got the following scenario. Somewhere there is a DynamicResource with color. This color determines background of windows and basing on that color I want to choose right icons to display (bright or dark).
I imagine the following scenario:
- The color changes, triggering a change in my class
- My class checks, which icon set should be chosen
- It forces all users of these icons to reload them.
I guess, that this should be doable using WPF mechanisms. The problem is, that I don't quite know, how to build architecture, which will do such processing.
- Capturing color change. I guess, that I can write a class with a
DependencyPropertycalled, say,BackgroundColorand then attach that color through aDynamicResource. This way I can capture the color change using thePropertyChangedCallback. - Internal processing is easy.
- I have to expose my icons, such that they will be attachable through the
DynamicResourcemechanism. How? By some kind of collection? Each one by its own DependencyProperty? - I have to notify all users of these icons, that they have changed. How? By IObservableCollection? Calling NotifyPropertyChanged on each property representing an icon? Maybe in some other way?
If there's a simpler way to achieve the goal I presented, I'll gladly hear it :)
You could just create a light and a dark WPF Theme and then switch between them dependant on the colour currently set as the
backgroundcolour. Using this method, WPF will take care of all of the icon updates.If you want to create your own system, you can use the
DependencyPropertysystem to help you:Backgroundcolour is changed:You can simply add a
PropertyChangedCallbackhandler to the currentBackgroundproperty:Exposing Icons and notifying the UI:
You can create a class that holds a
stringproperty to data bind to eachImage.Sourceproperty in the following format:As long as this class implements the
INotifyPropertyChangedinterface, then all you need to do is to change thesestringvalues and the UI will automatically update with the new icons or images.