Mark
Mark

Reputation: 14930

WPF apply a colour theme based on a binding value

I have a rather detailed user control has is made up of several sections, these sections has a specific blue theme applied to them, but I want to swap all of the Grids/Borders/Rectangles/etc... colours to be a green version of the same theme based on a binding in the DataContext.

Obviously I could use a converter for each Fill/Background property of the elements, but that seems very annoying.

In my converter (or XAML), can I apply a Style somehow to my user control that will just set the Fill/Background/etc... properties of my elements, essentially applying a colour theme?

Upvotes: 0

Views: 239

Answers (1)

user523650
user523650

Reputation:

You can set this in a style, making all Rectangles have a certain color.

In a resource dictionary I have:

<LinearGradientBrush x:Key="Windowsbackground" EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="Black" Offset="0.259"/>
    <GradientStop Color="#FF7691CD" Offset="1"/>
</LinearGradientBrush>

And then in my user control:

<UserControl x:Class="Test.Views.TestView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    MinHeight="300" MinWidth="300" Background="{DynamicResource Windowsbackground}">

Upvotes: 1

Related Questions