I am building an application using Prism 6, but I am new to MVVM, data binding and all these design patterns. In the application, I have a requirement to display different colours depending on the value of some of the properties of my view model.
To do so, I have a few SolidColorBrush in a resource dictionary like so: <SolidColorBrush x:Key="{x:Static status:Status.notViewed}">#FFe74856</SolidColorBrush>
Then in my view, I use: prism:ViewModelLocator.AutoWireViewModel="True"
to have it wired to the corresponding view model. I also use binding on a canvas (but that could be a grid or anything else, I don't really care) like this: <Canvas Background="{Binding B}" Margin="5" />
. As a side note, I have other elements bound to other properties, like a textblock bound to a string to display the date, and that works fine.
Now, in my view model I create the corresponding property B
for the binding public SolidColorBrush B = (SolidColorBrush)Application.Current.Resources[Status.notViewed];
.
When I run my application, the canvas stays white... However I am quite sure that B
contains a brush because I output its content in the constructor of the view model (Console.WriteLine("Color: {0}", B.ToString());
0 and I get the right value.
What am I doing wrong?
Thanks