Search code examples
c#xmlwpfresourcedictionary

WPF C# change resource dictionary accent color in code


i have a TextBox enter image description here The textbox highlights when selected, & uses the accent color from the resource dictionary in app.xaml

                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Green.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />

& if the username is less than 8 characters i'd like the accent color to turn to red, is there any way of doing this?


Solution

  • You'll have to overwrite the template for that textbox locally to add a datatrigger that triggers on a IValueConverter. Without seeing the template in question i can't really be more specific as we can't know how the accent is set up.
    Further reading: