2

Given a Settings.settings file that contains one or more SolidColorBrush entries on it with Application scope, how can I bind these values to XAML style templates?

For instance, I'll have a SolidColorBrush named MyAppColor with #FF0091D2 as value and a custom Button style template, where I want the Background to have the color from MyAppColor. How can I achieve this?


I have already tried adding a namespace (?) to the xaml file, like this:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:properties="clr-namespace:namespace.Properties"

Then tried to use the properties like this:

Background="{x:Static properties:Settings.Default.MyAppColor}"

But it says it can't have nested types.

auhmaan
  • 726
  • 1
  • 8
  • 28

1 Answers1

1

while Settings.Default is static, MyAppColor property isn't. (Settings.Default is a Singletone effectively). Use {x:Static} extension to set Binding.Source and provide Binding.Path as usual:

Background="{Binding Path=MyAppColor, Source={x:Static properties:Settings.Default}}"
ASh
  • 34,632
  • 9
  • 60
  • 82