1

I got a "settings" class (in a ownmade subfolder "etc" (in Visual studio)) it has a Boolean propertie named "boobackcolorred"(value = TRUE in the first form it puts it to true). Now I am making a WPF window for my settings and I want to use a checkbox where you can change the value of the boalean. I want to do this in the "XAML" way.(I can do it by making the event checked & unchecked but I don t want to do it that way.)

settings.cs: (in the "etc" folder I created in VS)

  class settings
    {

        public static Boolean boobackcolorred{ get; set; }
        ... // some extra code that does nothing with this, some xml reading and saving but doesn t matter for this issue.
    }

Now I am trying to do this with this xaml checkbox

 <CheckBox Content="Red Background?" Name="chbbackgroundred" IsChecked="{Binding etc.settings.boobackcolorred,Mode=TwoWay}" ></CheckBox>

OFC this isn t going to work I tried many ways of getting this to work. tried to include stuff like this:

xmlns:settings="clr-namespace:etc.myapp.settings"

also tried to bind the datacontext of the grid where the checkbox is in but no luck.

I know this can t be hard. However the answer will be greatly appreciated.

PS: it should be twoway binded so if unchecked the static boolean becomes false.

Maximc
  • 1,722
  • 1
  • 23
  • 37

2 Answers2

2

The problem is that it's a static property. Possible workaround in the answer here:

Binding to static property

Community
  • 1
  • 1
Mark
  • 1,784
  • 16
  • 26
0

Use IValueConverter interface.

<CheckBox IsChecked="{Binding Path=MyProperty, Converter={StaticResource ChbCheckedConverter}}"/>

Tutorial for using ValueConverters in WPF

JiKra
  • 1,618
  • 3
  • 29
  • 45