The best place for styles is the resource dictionary referenced by the App.xaml application.
Resource Dictionary ("StyleResources.xaml" in this example):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="TextBlockRightAlign" TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Right" /> </Style> <Style x:Key="TextBlockTitle" TargetType="TextBlock"> <Setter Property="FontSize" Value="20" /> <Setter Property="FontWeight" Value="Bold" /> </Style> </ResourceDictionary>
Link to style dictionary in App.xaml:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="StyleResources.xaml"/> </ResourceDictionary.MergedDictionaries> <ValueConverters:PriceConverter x:Key="PriceConverter"/> </ResourceDictionary> </Application.Resources>
Using the definition in a datagrid (column formatting here, but should also work for headers):
<data:DataGridTextColumn Header="Charge" Width="100" Binding="{Binding Charge, Mode=TwoWay, Converter={StaticResource PriceConverter}}" ElementStyle="{StaticResource TextBlockRightAlign}" />
Note that the element inside the cell is a TextBlock, so you can use a style with the target type of TextBlock.
source share