Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:18+00:00 2026-05-23T20:10:18+00:00

I have two brushes declared in my ResourceDictionary and I would like the user

  • 0

I have two brushes declared in my ResourceDictionary and I would like the user to select which background they want to see on the main window.

Resource Dictionary Brushes:
x:Key="LightBlueMainWindow"
x:Key="DarkBlueMainWindow"

Window:
Background="{DynamicResource LightBlueMainWindow}">

I have a project User Setting defined ‘MainBackground’ which is a string and can contain either key (LightBlueMainWindow or DarkBlueMainWindow).

What is the best way to dynamically set the background based on the user setting in XAML?

EDIT

I need to mention that I need to access this brush from many different user controls and windows throughout the application. I don’t want to set a property on every single place I want to set this brush.

Also, the brushes are pre-defined and not just a color like this

<LinearGradientBrush x:Key="LightBlueMainWindow" EndPoint="0.5,1" 
                     MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
    <LinearGradientBrush.GradientStops>            
        <GradientStopCollection>
            <GradientStop Color="#FFE9EFF3" />
            <GradientStop Color="#FF84A1B8" Offset="1"/>
        </GradientStopCollection>
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:10:19+00:00Added an answer on May 23, 2026 at 8:10 pm

    It will require a couple of steps

    You’ll need a converter since you can’t bind x:Key of a StaticResource or DynamicResource. For the converter to be able to get easy access to the resources they should be added at appliaction level

    <Application ...>
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="BrushesDictionary.xaml"/>
                </ResourceDictionary.MergedDictionaries>
                <local:ApplicationResourceKeyConverter x:Key="ApplicationResourceKeyConverter"/>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    

    ApplicationResourceKeyConverter

    public class ApplicationResourceKeyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string key = value as string;
            return Application.Current.TryFindResource(key);
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Then you can bind the MainWindow Background property to the user settings string MainBackground like

    <Window ...
            xmlns:ProjectProperties="clr-namespace:YourProjectName.Properties" 
            Background="{Binding Source={x:Static ProjectProperties:Settings.Default},
                                 Path=MainBackground,
                                 Converter={StaticResource ApplicationResourceKeyConverter}}">
        <!--...-->
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have some logic, which defines and uses some user-defined types, like these: class
I have two classes, and want to include a static instance of one class
I have two spreadsheets... when one gets modified in a certain way I want
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
I have two insert statements, almost exactly the same, which run in two different
I have an Adorner which adornes a Border (please see screenshot below). The MouseDown
i have two richtextboxes one below the other in my application.when the user start
I have two distinct databases as a source for a Silverlight RIA application. They
I have two tables in my database, table1 and table2. They are identical. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.