Home > DeveloperSection > Forums > How to change the window.resource style setter?
Tanuj Kumar

Total Post:134

Posted on    March-26-2014 3:53 AM


 1 Reply(s)
 1125  View(s)
Rate this:

<Window.Resources >

        <Style x:Name="stylepropery" x:Key="BaseContentControlStyle" TargetType="{x:Type ContentControl}">

            <Setter Property="Foreground" Value="{DynamicResource MyFillBrush}"  />


        <Style  TargetType="{x:Type Label}" BasedOn="{StaticResource BaseContentControlStyle}" />

     <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource BaseContentControlStyle}" />


which is applying common font color to all the labels and textboxes now i want to change the color of font from code behind but some how its not applying i just want to change setter propery value

 Setter setter = new Setter(ContentControl.ForegroundProperty, dt.Rows[0]["value"]);

 Style style = this.FindResource("BaseContentControlStyle") as Style;


I have used this but not succeeded.

Pravesh Singh

Total Post:411

Posted on    March-26-2014 4:28 AM

Hi Tanuj,

Try this code this may help you

Style style = new Style(typeof(ContentControl));

style.Setters.Add(new Setter(ContentControl.ForegroundProperty, Brushes.Green)); Resources["BaseContentControlStyle"] = style;

Don't want to miss updates? Please click the below button!

Follow MindStick