karl.r
karl.r

Reputation: 971

Binding fill to color resource conditionally

I am trying to bind the fill of a rectangle to a color in a resource dictionary. In blend it is very easy to bind to one color.

But in my viewmodel I have an enum with 3 'categories' and I would like the rectangles fill to be different based on the value of this enum, and keep all the colors in the resource dictionary.

Has anyone tried doing this? Would it be a binding converter that does enum -> color resource?

Solved: Accessing colors in a resource dictionary from a value converter

Upvotes: 0

Views: 357

Answers (1)

Mick N
Mick N

Reputation: 14882

Your converter can return a SolidColorBrush. You can instantiate it using from a color in the resource dictionary like this for example.

SolidColorBrush b = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];

Upvotes: 2

Related Questions