M
M
Michael2015-05-06 16:59:56
WPF
Michael, 2015-05-06 16:59:56

How to set Color from Settings?

There are colors and brushes of this kind:

<SolidColorBrush x:Key="MyBrush" Color="#FF00FF00"/>
<Color x:Key="MyColor">#FF00FFFF</Color>

The colors themselves are stored in the application settings (the Settings.settings file).
Question. How to set colors in Color and SolidColorBrush from application settings file? It was not possible to set them through the binding ({Binding MyColor, Source={x:Static res:Settings.Default}}).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2015-05-06
@gmikhail94

In code, create a System.Windows.Media.Color object based on the information in Settings and assign it to the desired property or resource.
Your binding doesn't work because #FF00FFFF is not a color but a string. When described in Xaml, the converter automatically works from text to Color. When setting a binding for such a conversion, you must explicitly specify the converter. As far as I understand, System.Windows.Media.ColorConverter is used there. You need to specify an instance of this class in the Converter parameter or write your own converter from text to color or brush.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question