Jatinder Walia
Jatinder Walia

Reputation: 141

Set Foreground of a GroupBox header template using a property from App.xaml.cs

This is the Style for a WPF GroupBox. I am able to set the value of Groupbox background and Groupbox border color from properties defined in App.xaml.cs as shown.

<Style x:Key="StyleGroupBox1" TargetType="GroupBox">
            <Setter Property="Background" >
                <Setter.Value>
                    <Binding Path="GroupBox_Background" Source="{x:Static Application.Current}"/>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <Binding Path="Groupbox_BorderColor" Source="{x:Static Application.Current}"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Margin" Value="1,1,1,1"/>
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" FontWeight="Bold" FontFamily="Palatino Linotype" FontSize="17" Foreground="DarkRed" FontStyle="Italic">

                        </TextBlock>

                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

How to set the ForeGround of GroupBox's header Template similar to the way in which i have set the background and bordercolor of the Groupbox(ie from a property defined in my app.xaml.cs)?ie currently the header text is set to DarkRed,but how to set it using a property in my App.xaml.cs?

Upvotes: 0

Views: 624

Answers (1)

Vadim Moskvin
Vadim Moskvin

Reputation: 51

<TextBlock 
                Text="{Binding}" 
                FontWeight="Bold" 
                FontFamily="Palatino Linotype" 
                FontSize="17" 
                Foreground="{Binding Source={x:Static Application.Current}, Path=Groupbox_HeaderForegroundColor}" 
                FontStyle="Italic">

Upvotes: 1

Related Questions