I have implemented a light/dark theme in my app where the user can either press the light or dark button and all the app colours will change. I do this by binding a SolidColorBrush to the background and foreground of each element e.g.
In viewmodel:
private SolidColorBrush fontColour;
public SolidColorBrush FontColour
{
get { return fontColour; }
set
{
fontColour = value;
OnPropertyChanged(nameof(FontColour));
}
}
In xaml:
<TextBox Text="{Binding EventLog}"
Foreground="{Binding FontColour}"
Background="{Binding ColourTheme5}"/>
This works as expected. However, when I try to do the same thing within TextBox.Resources, the binding does not work at all e.g.
(binding for TextControlForegroundPointerOver does not work)
<TextBox Text="{Binding EventLog}"
Foreground="{Binding FontColour}"
Background="{Binding ColourTheme5}">
<TextBox.Resources>
<SolidColorBrush x:Key="TextControlForegroundPointerOver"
Color="{Binding FontColour}"
Opacity="1" />
</TextBox.Resources>
</TextBox>