In my program I have three distinct UI states (Normal, Success, and Error) and in each one the controls are visible/hidden, enabled/disabled, the colors change, labels say different things…etc. and in my code-behind I basically want to be able to say ChangeWindowState(UI.Normal);
So my question is how best to implement the control changes for each state?
Of course I could manually change the controls in the code-behind, but I wonder if maybe there is a better way by using wpf themes or styles. Then maybe I could just set the window to use the ‘Error’ theme, which I have pre-defined. I don’t really understand them at the moment so I may be using the terminology wrong, but I would appreciate if someone could point me in the right direction how best to do something like this.
Thanks!
There are many ways to approach this, of course. If you had a program-state ‘object model’ you could use some combination of DataTemplates and DataTriggers. Assuming this is not the case, here’s another approach: You referred to a window, so suppose you define a ‘dependency property’ in your window class like this:
Now you can change pretty much any property of any element of the window (including the window itself), by either direct binding or a trigger. Here’s an example of changing the window’s background color via a property trigger: