I got a problem with changing color of Toggle in TreeView programmatically.
I defined in ResourceDictionary SolidColorBrush with:
<SolidColorBrush x:Key="FillBrush" Color="#000000" />
i created style for toggleButton in ResourceDictionary as well:
<Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid Width="auto" Height="auto" Background="Transparent" ShowGridLines="True">
<Path Fill="{StaticResource FillBrush}" x:Name="ExpandPath" HorizontalAlignment="Center" VerticalAlignment="Center"
Data="M 0 0 L 0 2 L 6 0 z M 6 2 L 6 0 L 0 2 z">
</Path>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Data" TargetName="ExpandPath" Value="M 0 0 L 0 8 L 2 0 z M 2 8 L 2 0 L 0 8 z"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
In code i am trying to change programmatically the value of the FillBrush key:
SolidColorBrush cc = (SolidColorBrush)Resources["FillBrush"];
cc.Color=c.Color;
but when i change it, the Toggle button doesnt change.
Any hints how to change color of existing component? I am a bit confused of templating the components throught ResourceDictionary so i guess its something wrong in there. Thanks for all help
EDIT : in code i am "saying" use StaticResource. I tried it with DynamicResource as well, but nothing happend and the color value didnt change.
EDIT 2 : if i check the value in the FillBrush resource with:
MessageBox.Show(((SolidColorBrush)Resources["FillBrush"]).Color.ToString());
the value is replaced with the new value. So it works. In this case there must be something wrong with aplying it in the ToggleButton style.