public
class
AttachedProperties
{
static
bool
GetIsFocussed(DependencyObject obj)
return
(
)obj.GetValue(IsFocussedProperty);
}
void
SetIsFocussed(DependencyObject obj,
value)
obj.SetValue(IsFocussedProperty, value);
readonly
DependencyProperty IsFocussedProperty =
DependencyProperty.RegisterAttached(
"IsFocussed"
,
typeof
),
(AttachedProperties),
new
UIPropertyMetadata(
false
));
<
Window.Resources
>
ControlTemplate
x:Key
=
"DifferentHeaderTemplate"
TargetType
"{x:Type DataGridRowHeader}"
Grid
Background
"Red"
Width
"10"
/>
</
Style
"DataGridRowHeaderStyle1"
Style.Triggers
DataTrigger
Binding
"{Binding (local:AttachedProperties.IsFocussed), Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}}"
Value
"true"
Setter
Property
"Template"
"{DynamicResource DifferentHeaderTemplate}"
"DataGridRowHeaderStyle2"
"Background"
"DataGridRowHeaderStyle3"
StackPanel
<!-- Changing DataGridRowHeader ControlTemplate for selected cell -->
DataGrid
Margin
x:Name
"myDataGrid1"
ItemsSource
"{Binding AllItems}"
RowHeaderStyle
"{DynamicResource DataGridRowHeaderStyle1}"
DataGrid.CellStyle
"{x:Type DataGridCell}"
"IsSelected"
"{Binding (local:AttachedProperties.IsFocussed), Mode=OneWayToSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}}"
<!-- Changing DataGridRowHeader Properties for selected cell -->
"myDataGrid2"
"{DynamicResource DataGridRowHeaderStyle2}"
<!-- Changing DataGrid.RowHeaderStyle -->
"myDataGrid3"
DataGrid.Style
"DataGrid"
"{Binding (local:AttachedProperties.IsFocussed), Mode=OneWay, RelativeSource={RelativeSource Self}}"
"DataGrid.RowHeaderStyle"
"{DynamicResource DataGridRowHeaderStyle3}"
"{Binding (local:AttachedProperties.IsFocussed), Mode=OneWayToSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}"