I have a template of an elliptical button in my "ButtonStyles.xaml" resource dictionary. This is part of the code:
<SolidColorBrush x:Key="brush" Color="Red"/>
<Style TargetType="Button" x:Key="MyButtonStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Target="ellipse.(Shape.Fill)" Value="{StaticResource ResourceKey=brush}">
</Setter>
<Setter Target="ellipse.(Shape.Stroke)" Value="{x:Null}"/>
</VisualState.Setters>
</VisualState>
[...]
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="ellipse"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here is the button in the MainPage:
<Button x:Name="toggle" Content="" HorizontalAlignment="Left" Height="132" Margin="40,146,0,0" VerticalAlignment="Top" Width="132" Style="{StaticResource MyButtonStyle}"/>
Now I'd like to change the brush resource from the c# code. To do this I tried as follows :
Application.Current.Resources["brush"] = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 125, 126, 126));
While the brush resource effectively changes the colour of the ellipse doesn't. I think that the problem is that I should not change the colour in the template but in the actual MainPage button. Is this the problem? How can I do that?