In my project i have a datagridcell control which i want to change its background value when the client click it. the DataGridCell style is inherit from a Resource Dictionary.
The problem is, the background doesn't change at all.
At first i thought maybe my trigger event is wrong, but event when i set the background directly on the control and remove the style, the background stays Transparent.
Here is the declaration of the control:
<Grid Style="{DynamicResource GridBrushColorByTheme}">
<WrapPanel>
<DataGridCell Content="1" Style="{DynamicResource cellStyle}"/>
</WrapPanel>
</Grid>
And here is the style (Please look at the "Click Style" in the buttom of the style):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="cellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="10,10,0,0" />
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="36"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Border>
<Border x:Name="border"
BorderBrush="Transparent"
BorderThickness="0"
Padding="3"
CornerRadius="0">
<ContentPresenter />
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!--Steady Foreground-->
<DataTrigger Binding="{Binding Source={StaticResource odpSettings},Path=Theme, Mode=OneWay}"
Value="Dark">
<Setter Property="Foreground" Value="{DynamicResource DarkThemeForegroundColor(White)}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Source={StaticResource odpSettings},Path=Theme, Mode=OneWay}"
Value="Light">
<Setter Property="Foreground" Value="{DynamicResource LightThemeForegroundColor(Black)}"/>
</DataTrigger>
<!--Hover Style - Drak!-->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
<Condition Binding="{Binding Source={StaticResource odpSettings},Path=Theme, Mode=OneWay}" Value="Dark"/>
</MultiDataTrigger.Conditions>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{DynamicResource LightThemeBgColor}" Background="{DynamicResource LightThemeBgColor}" CornerRadius="5">
<TextBlock Padding="3" Text="{TemplateBinding Content}" TextAlignment="Center">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="{x:Null}"
Storyboard.TargetProperty="(TextBlock.Opacity)"
From="1.0" To="0.0" Duration="0:0:0.7"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource LightThemeForegroundColor(Black)}"/>
</MultiDataTrigger>
Hover Style - Light!
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
<Condition Binding="{Binding Source={StaticResource odpSettings},Path=Theme, Mode=OneWay}" Value="Light"/>
</MultiDataTrigger.Conditions>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{DynamicResource DarkThemeBgColor}" Background="{DynamicResource DarkThemeBgColor}" CornerRadius="5">
<TextBlock Padding="3" Text="{TemplateBinding Content}" TextAlignment="Center" >
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="{x:Null}"
Storyboard.TargetProperty="(TextBlock.Opacity)"
From="1.0" To="0.0" Duration="0:0:0.7"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource DarkThemeForegroundColor(White)}"/>
</MultiDataTrigger>
<!--Click Style!-->
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource OrangeThemeBgColor}"/>
<Setter Property="BorderBrush" Value="{DynamicResource OrangeThemeBgColor}"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
Can anyone please help me? how am i suppouse to set the background when clicking the cell?
Thanks, oron!
What I have tried:
.......................................................................