Global style can't be overridden - wpf

I have this defined in my app.xaml
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="FontFamily" Value="Cailibri"></Setter>
</Style>
and this defined in Window1.xaml
<Style x:Key="BASE">
<Setter Property="Control.FontSize" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=MyFontSize}">
</Setter>
<Setter Property="Control.FontFamily" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=MyFontFamily}">
</Setter>
<Setter Property="Control.HorizontalAlignment" Value="Left">
</Setter>
</Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource BASE}">
</Style>
<Style TargetType="lc:LayoutItem" BasedOn="{StaticResource BASE}">
<Setter Property="LabelStyle">
<Setter.Value>
<Style TargetType="lc:LayoutItemLabel" BasedOn="{StaticResource BASE}">
</Style>
</Setter.Value>
</Setter>
</Style>
<lc:LayoutControl x:Name="HeadLayout" lc:LayoutControl.CustomizationLabel="test" ItemInsertionPointIndicatorStyle="{StaticResource myInsertionPointIndicator}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
AllowNewItemsDuringCustomization="False" AllowAvailableItemsDuringCustomization="True" Orientation="Horizontal">
<lc:LayoutGroup Orientation="Vertical" View="Group" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<lc:LayoutItem Label=" CDFEG " x:Name="StoreName" >
<TextBlock TextWrapping="Wrap" Text="ABCDEFG"/>
</lc:LayoutItem>
</lc:LayoutGroup>
</lc:LayoutControl>
when i change the fontsize or fontfamily property , it works fine when TextBlock isn't defined in app.xaml. I've searched this for a long time , but there's not quite a solution to me. any advice will help, thx.

It's been resolved, using DataTemplate.
<Style TargetType="lc:LayoutItem" x:Key="myLayoutItemStyle" BasedOn="{StaticResource BASE}">
<Setter Property="LabelTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" >
<TextBlock.Style>
<Style BasedOn="{StaticResource BASE}">
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
check it here, http://documentation.devexpress.com/#WPF/DevExpressXpfLayoutControlLayoutItem_LabelTemplatetopic.

Related

cannot Set the datasource on a datapresenter that has items added explicitly through data items collection

I have a collection in MainViewModel ,as
View = new List<Group>
{
new Group
{
Name = "Sagar Yadwad",GroupName = string.Empty,IsEnabled = true,LdapStatus="Pending"
},
new Group
{
Name = "Sagar Yadwad1",GroupName = string.Empty,IsEnabled = false,LdapStatus="Pending"
}
};
View1 = new ListCollectionView(View);
View1.Filter = (e) =>
{
Group g = e as Group;
return g.IsEnabled;
};
Now, I am binding my above ViewModel to my XamDatagrid and the code is as follow :-
<igDp:XamDataGrid x:Name="XamDataGridGroup" DataSource="{Binding View1}" Width="950" FontStyle="Normal" FontFamily="Siemens Sans" Background="#F2F2F2" RecordFilterDropDownPopulating="GroupDataGrid_OnRecordFilterDropDownPopulating" GroupByAreaLocation="None" AllowDrop="True" IsSynchronizedWithCurrentItem="True" UpdateMode="OnUpdate" >
<UserControl>
</UserControl>
<igDp:XamDataGrid.Resources>
<Style TargetType="{x:Type igDp:DataRecordPresenter}">
<Setter Property="IsSelected" Value="{Binding DataItem.IsSelected, Mode=TwoWay}"/>
</Style>
<Style TargetType="Button" x:Key="{ComponentResourceKey {x:Type igDp:XamDataGrid}, ButtonStyle}" BasedOn="{StaticResource BaseButtonStyle}"/>
<Style TargetType="igWindows:PopupResizerBar" >
<Setter Property="Visibility" Value="Hidden"></Setter>
</Style>
</igDp:XamDataGrid.Resources>
<igDp:XamDataGrid.FieldLayoutSettings>
<igDp:FieldLayoutSettings AllowRecordFixing="No"
AllowDelete="False"
HighlightAlternateRecords="False"
RecordSelectorLocation="None"
SelectionTypeRecord="Single"
SelectionTypeCell="Single" FilterUIType="LabelIcons"
AutoGenerateFields="False" AllowFieldMoving="No"
RecordSelectorExtent="1"/>
</igDp:XamDataGrid.FieldLayoutSettings>
<igDp:XamDataGrid.FieldSettings >
<igDp:FieldSettings
LabelTextWrapping="NoWrap"
FilterLabelIconDropDownType="MultiSelectExcelStyle"
AllowRecordFiltering="True" AllowCellVirtualization="False"
AllowLabelVirtualization="False" Width="Auto" CellWidth="100"
CellMinWidth="50"/>
</igDp:XamDataGrid.FieldSettings>
<igDp:XamDataGrid.FieldLayouts>
<igDp:FieldLayout>
<!--<igDp:FieldLayout.Fields>
<igDp:Field Name="Name" AllowEdit="False" AllowRecordFiltering="True"></igDp:Field>
</igDp:FieldLayout.Fields>-->
<igDp:UnboundField Width="300" Label="{LocText props:Resources.GROUPLIST_NAME}" BindingPath="Name" ToolTip="{LocText props:Resources.GROUPLIST_NAME}">
<igDp:UnboundField.Settings>
<igDp:FieldSettings>
<igDp:FieldSettings.LabelPresenterStyle >
<Style TargetType="igDp:LabelPresenter" BasedOn="{StaticResource GmsLabelStyle }">
<Setter Property="AutomationProperties.AutomationId" Value="Groups_Column"></Setter>
</Style>
</igDp:FieldSettings.LabelPresenterStyle>
<igDp:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDp:CellValuePresenter}">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="igDp:CellValuePresenter">
<TextBlock TextAlignment="Left" Text="{Binding Path=DataContext.DataItem.Name, RelativeSource={ RelativeSource Mode=TemplatedParent}}"
VerticalAlignment="Center" />
<!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDp:FieldSettings.CellValuePresenterStyle>
</igDp:FieldSettings>
</igDp:UnboundField.Settings>
</igDp:UnboundField>
<igDp:UnboundField Width="350" Label="{LocText props:Resources.GROUPLIST_LDAP_USERS}" BindingPath="GroupName" ToolTip="{LocText props:Resources.GROUPLIST_LDAP_USERS}">
<igDp:UnboundField.Settings>
<igDp:FieldSettings>
<igDp:FieldSettings.LabelPresenterStyle >
<Style TargetType="igDp:LabelPresenter" BasedOn="{StaticResource GmsLabelStyle }">
<Setter Property="AutomationProperties.AutomationId" Value="Group_Name"></Setter>
</Style>
</igDp:FieldSettings.LabelPresenterStyle>
<igDp:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDp:CellValuePresenter}">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="igDp:CellValuePresenter">
<TextBlock AllowDrop="True" Text="{Binding Path=DataContext.DataItem.GroupName, RelativeSource={ RelativeSource Mode=TemplatedParent}}"
VerticalAlignment="Center" TextAlignment="Center" />
<!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDp:FieldSettings.CellValuePresenterStyle>
</igDp:FieldSettings>
</igDp:UnboundField.Settings>
</igDp:UnboundField>
<igDp:UnboundField Width="100" Label="{LocText props:Resources.GROUPLIST_SYNC}" BindingMode="TwoWay" BindingPath="IsEnabled" Converter="{StaticResource BoolToUMDirectoryFilter}" ConverterParameter="Enabled" ToolTip="{LocText props:Resources.GROUPLIST_SYNC}">
<igDp:UnboundField.Settings>
<igDp:FieldSettings AllowEdit="True">
<igDp:FieldSettings.LabelPresenterStyle >
<Style TargetType="igDp:LabelPresenter" BasedOn="{StaticResource GmsLabelStyle }">
<Setter Property="AutomationProperties.AutomationId" Value="Group_SYNC"></Setter>
</Style>
</igDp:FieldSettings.LabelPresenterStyle>
<igDp:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDp:CellValuePresenter}">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="igDp:CellValuePresenter">
<CheckBox IsChecked="{Binding Path=DataContext.DataItem.IsEnabled, RelativeSource={ RelativeSource Mode=TemplatedParent}}"
HorizontalAlignment="Center" HorizontalContentAlignment="Center" Click="ButtonBase_OnClick">
</CheckBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDp:FieldSettings.CellValuePresenterStyle>
</igDp:FieldSettings>
</igDp:UnboundField.Settings>
</igDp:UnboundField>
<igDp:UnboundField Width="140" Label="{LocText props:Resources.GROUPLIST_LDAP_STATUS}" BindingPath="LdapStatus" ToolTip="{LocText props:Resources.GROUPLIST_LDAP_STATUS}">
<igDp:UnboundField.Settings>
<igDp:FieldSettings>
<igDp:FieldSettings.LabelPresenterStyle >
<Style TargetType="igDp:LabelPresenter" BasedOn="{StaticResource GmsLabelStyle }">
<Setter Property="AutomationProperties.AutomationId" Value="Group_Status"></Setter>
</Style>
</igDp:FieldSettings.LabelPresenterStyle>
<igDp:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDp:CellValuePresenter}">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="igDp:CellValuePresenter">
<TextBlock Text="{Binding Path=DataContext.DataItem.LdapStatus, RelativeSource={ RelativeSource Mode=TemplatedParent}}"
VerticalAlignment="Center" TextAlignment="Center"/>
<!--Visibility="{Binding Path=Parent.IsNameChangeable}"/>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDp:FieldSettings.CellValuePresenterStyle>
</igDp:FieldSettings>
</igDp:UnboundField.Settings>
</igDp:UnboundField>
</igDp:FieldLayout>
</igDp:XamDataGrid.FieldLayouts>
</igDp:XamDataGrid>
I am getting an error saying that, ' cannot Set the datasource on a datapresenter that has items added explicitly through data items collection '. Any help would be much appreciated.
Thanks in advance,
Sagar Yadwad
Remove the UserControl from the XamDataGrid:
<igDp:XamDataGrid x:Name="XamDataGridGroup" DataSource="{Binding View1}" ...>
<UserControl>
</UserControl>
...

StaticResource alters border of TextBox

I needed a placeholder for TextBox and found this working code:
<Style x:Key="placeHolder" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox Text="{Binding Path=Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
x:Name="textSource"
Background="Transparent"
Panel.ZIndex="2"
BorderThickness="0,0,0,1"/>
<TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="LightGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This is my TextBox:
<TextBox x:Name="isci_tb" HorizontalAlignment="Left" Height="25" Margin="0,0,0,0" TextWrapping="Wrap"
VerticalAlignment="Center" Width="120" BorderThickness="0, 0, 0, 1" TextChanged="isci_tb_TextChanged" Tag="išči" Style="{StaticResource placeHolder}">
<TextBox.Background>
<ImageBrush/>
</TextBox.Background>
</TextBox>
Since I am new to XAML I don't see where or what changes the border of my button. I wish to only have the bottom border but instead all 4 borders are shown.
Set the BorderThickness property of the inner TextBox in your template to 0:
<Style x:Key="placeHolder" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox Text="{Binding Path=Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
x:Name="textSource"
Background="Transparent"
Panel.ZIndex="2"
BorderThickness="0,0,0,1"/>
<TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1"
BorderThickness="0">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="LightGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

How to use different ItemsControl.ItemContainerStyle for different ItemsPanelTemplate

I have an ItemsControl which uses different ItemsPanelTemplate based on certain condition. I want to have different ItemContainerStyle for each ItemsPanelTemplate (in fact, I want ItemsContainerStyle for only one of the templates). How can I achieve that? Here is the code I am using:
<UserControl.Resources>
<ItemsPanelTemplate x:Key="UGridItemsPanelTemplate">
<UniformGrid Name="MyUGrid" Columns="{Binding Columns}" Rows="{Binding Rows}"/>
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="GridItemsPanelTemplate">
<Grid Name="MyGrid" Loaded="MyGrid_Loaded"/>
</ItemsPanelTemplate>
</UserControl.Resources>
<Grid>
<!--ItemList has 1000+ items if IsMap is FALSE; using ItemsConatinerStyle in this case slows the UI down-->
<ItemsControl Name="MyPresenter" ItemsSource="{Binding ItemList}" Tag="{Binding IsMap}">
<ItemsControl.Style>
<Style TargetType="{x:Type ItemsControl}">
<Setter Property="ItemsPanel" Value="{StaticResource UGridItemsPanelTemplate}"/>
<Style.Triggers>
<Trigger Property="Tag" Value="TRUE">
<!--I want to use ItemContainerStyle only for this template-->
<Setter Property="ItemsPanel" Value="{StaticResource GridItemsPanelTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
<!--Use this style only if IsMap is TRUE-->
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Grid.Row" Value="{Binding GridRow}"/>
<Setter Property="Grid.Column" Value="{Binding GridColumn}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="Border1" Background="{Binding BorderVisible}"
BorderThickness="1" Padding="{Binding PaddingVal}">
<Button Name="ItemButton" Content="{Binding Label}" IsEnabled="{Binding IsButtonEnabled}" CommandParameter="{Binding}"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
Thanks,
RDV
I found a way, When IsMap is TRUE, set ItemsContainerStyle along with ItemsPanel. Updated code is posted below:
<UserControl.Resources>
<ItemsPanelTemplate x:Key="UGridItemsPanelTemplate">
<UniformGrid Name="MyUGrid" Columns="{Binding Columns}" Rows="{Binding Rows}"/>
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="GridItemsPanelTemplate">
<Grid Name="MyGrid" Loaded="MyGrid_Loaded"/>
</ItemsPanelTemplate>
<Style x:Key="ClusterGridContainerStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Grid.Row" Value="{Binding UnitGridRow}"/>
<Setter Property="Grid.Column" Value="{Binding UnitGridColumn}"/>
</Style>
</UserControl.Resources>
<Grid>
<!--ItemList has 1000+ items if IsMap is FALSE-->
<ItemsControl Name="MyPresenter" ItemsSource="{Binding ItemList}" Tag="{Binding IsMap}">
<ItemsControl.Style>
<Style TargetType="{x:Type ItemsControl}">
<Setter Property="ItemsPanel" Value="{StaticResource UGridItemsPanelTemplate}"/>
<Style.Triggers>
<Trigger Property="Tag" Value="TRUE">
<!--I want to use ItemContainerStyle only for this template-->
<Setter Property="ItemsPanel" Value="{StaticResource GridItemsPanelTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource ClusterGridContainerStyle}"/>
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="Border1" Background="{Binding BorderVisible}"
BorderThickness="1" Padding="{Binding PaddingVal}">
<Button Name="ItemButton" Content="{Binding Label}" IsEnabled="{Binding IsButtonEnabled}" CommandParameter="{Binding}"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>

WPF- trigger target not found

I have own style on listbox, I use in style data template and also control template.
In data template I create listbox item with some textboxes. In control template I want create a trigger which change foreground color of some textbox if listbox item is selected.
Here is some from style:
<Style x:Key="lbStyle" TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid Name="MainGrid">
<TextBlock Name="tbName" Text="{Binding Value.nick}"
Grid.Column="0" Grid.Row="0" Margin="2,2,2,2"
FontSize="13" FontWeight="Medium"></TextBlock>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="tbName" Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Problem is, I get compile error : Cannot find the Trigger target tbName.
<Style TargetType="ListBox">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Margin="2" FontSize="13" FontWeight="Medium">
<TextBlock.Style>
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected}" Value="True">
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Your code of template is incorrect. You apply ListBoxItem template to ListBox template. Also, you didn't add anything inside ControlTemplate.
I have rewrited it:
<Style x:Key="itemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ContentPresenter x:Name="itemContent"/>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="itemContent" Property="TextBlock.Foreground" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ListBox with applied style:
<ListBox ItemContainerStyle="{StaticResource itemStyle}" />

WPF templating/styling issue

Given this piece of XAML
<DockPanel>
<DockPanel.Resources>
<Style TargetType="{x:Type GroupBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<DockPanel>
<Border DockPanel.Dock="Top">
<Border.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground"
Value="Red" />
</Style>
</Border.Resources>
<ContentPresenter ContentSource="Header" />
</Border>
<ContentPresenter />
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DockPanel.Resources>
<GroupBox VerticalAlignment="Top"
Header="GroupBox header"
DockPanel.Dock="Top">
...
...
I would like to know why the group box header is not displayed in red letters.
I've already tried styling the Label type with no success either.
(sorry about the overly generic post title... I wasn't able to think of something more meaninful)
This code solved the problem:
<DockPanel>
<DockPanel.Resources>
<Style TargetType="{x:Type GroupBox}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="Label">
<Style.Setters>
<Setter Property="Foreground" Value="Red" />
</Style.Setters>
</Style>
</DataTemplate.Resources>
<Label Content="{Binding}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DockPanel.Resources>
<GroupBox VerticalAlignment="Top" Header="GroupBox header" DockPanel.Dock="Top">
...
...
However, I still don't know why the proposed code didn't worked.
It seems that the ContentPresenter doesn't use TextBlock to show the string you provide as header or explicitly sets its style, so the style you defined cannot be applied.
If you are certain that you will only use text as group box header, you can remove the ContentPresenter and use a TextBlock on your own.
<DockPanel>
<DockPanel.Resources>
<Style TargetType="{x:Type GroupBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<DockPanel>
<Border DockPanel.Dock="Top">
<Border.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red" />
</Style>
</Border.Resources>
<TextBlock Text="{TemplateBinding Header}"></TextBlock>
</Border>
<ContentPresenter />
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DockPanel.Resources>
<GroupBox VerticalAlignment="Top"
Header="GroupBox header"
DockPanel.Dock="Top"/>
</DockPanel>
try this:
<DockPanel.Resources>
<Style TargetType="{x:Type GroupBox}" >
<Setter Property="Foreground" Value="Red" />
</Style>
</DockPanel.Resources>
You don't need a templet for this. But if you demand on using a Templete, you probably have to set the Groupbox.HeaderTemplet not the GroupBox.Templet.
Edit:
This is what i got so far, but i keep getting an XamlPraseException.
<Style TargetType="{x:Type GroupBox}" >
<Setter Property="HeaderTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red"/>
</Style>
</StackPanel.Resources>
<TextBlock Text="{TemplateBinding GroupBox.Header}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Resources