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

  • SEARCH
  • Home
  • 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 8864989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:23:32+00:00 2026-06-14T16:23:32+00:00

I am working on a WPF application and I am trying to change colors

  • 0

I am working on a WPF application and I am trying to change colors during runtime. I tried the solution posted in this thread: WPF: Changing Resources (colors) from the App.xaml during runtime; however, the solution doesn’t seem to work.

I have 3 resource dictionaries defined

Colors1.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Color x:Key="BaseColor">#ffaa01</Color>
  <SolidColorBrush x:Key="BackgroundColorBrush" Color="{DynamicResource BaseColor}" />
</ResourceDictionary>

Colors2.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="BaseColor">#aaff01</Color>
<SolidColorBrush x:Key="BackgroundColorBrush" Color="{DynamicResource BaseColor}" />
</ResourceDictionary>

Colors3.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="BaseColor">#aa01ff</Color>
<SolidColorBrush x:Key="BackgroundColorBrush" Color="{DynamicResource BaseColor}" />
</ResourceDictionary>

All 3 resource dictionaries are located in a sub folder within the root of my application called “Resources”.

I have added the Colors1 resource dictionary to the Application resources (in the Application.xaml file) so that it is loaded by default.

Here is my Application.xaml:

<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
   <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="Colors1" Source="Resources/Colors1.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
   </Application.Resources>
</Application>

I have a Window in my application called “Window1” which contains a Grid and a ComboBox that allows you to switch between resource dictionaries.

Here is the xaml code for the Window1:

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Picture Orders" Height="600" Width="600"
xmlns:myProj="clr-namespace:TryingWPF">
<Window.Resources>
    <x:Array x:Key="ResourceNames" Type="sys:String"
             xmlns:sys="clr-namespace:System;assembly=mscorlib">
        <sys:String>Colors1</sys:String>
        <sys:String>Colors2</sys:String>
        <sys:String>Colors3</sys:String>
    </x:Array>
</Window.Resources>
<Grid x:Name="VisualRoot" Background="{DynamicResource BackgroundColorBrush}">
    <ComboBox x:Name="ResourceOptions" 
              ItemsSource="{StaticResource ResourceNames}" 
              SelectedIndex="0"
              VerticalAlignment="Top"
              HorizontalAlignment="Center"
              SelectionChanged="ResourceOptions_SelectionChanged"/>
</Grid>
</Window>

And here is the VB.NET code that handles the Selection Changed event for the ComboBox that should change the background color for the Grid in the Window:

Public Class Window1

   Private Sub ResourceOptions_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
    Dim resourceSource As String = String.Format("pack://application:,,,/Resources/{0}.xaml", ResourceOptions.SelectedValue)
    Dim newResourceDictionary As New ResourceDictionary()
    newResourceDictionary.Source = New Uri(resourceSource)
    Application.Current.Resources.MergedDictionaries.RemoveAt(0)
    Application.Current.Resources.MergedDictionaries.Insert(0, newResourceDictionary)

   End Sub
End Class

I’m not sure what I’m doing wrong.

How do I get the colors to change?

*Edit: *
Well, right after posting this question, I discovered that if I moved the Brush out of the color resource file and into the Window resources, the color would change upon switching resources.

However, If I move the brush to another ResourceDictionary, called ColorBrushes, and simply switch the Color ResourceDictionaries, it would not change colors.

In my main application, all of my brushes are defined in ResourceDictionaries, not within the windows or user controls themselves….so this is still a problem for me.

  • 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-06-14T16:23:33+00:00Added an answer on June 14, 2026 at 4:23 pm

    I solved the problem by changing the Colors dictionary and then changing the Brushes dictionary to the Brushes dictionary.

    Like so:

    Public Class Window1
    
     Private Sub ResourceOptions_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
       Dim resourceSource As String = String.Format("pack://application:,,,/Resources/{0}.xaml", ResourceOptions.SelectedValue)
       Dim newResourceDictionary As New ResourceDictionary()
       newResourceDictionary.Source = New Uri(resourceSource)
       Application.Current.Resources.MergedDictionaries.RemoveAt(0)
       Application.Current.Resources.MergedDictionaries.Insert(0, newResourceDictionary)
    
       Dim brushesResourceSource As String = "pack://application:,,,/Resources/ColorBrushes.xaml"
       Dim newBrushesResourceDictionary As New ResourceDictionary()
       newBrushesResourceDictionary.Source = New Uri(brushesResourceSource)
       Application.Current.Resources.MergedDictionaries.RemoveAt(1)
       Application.Current.Resources.MergedDictionaries.Insert(1, brushesResourceSource)
     End Sub
    End Class
    

    -Frinny

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a WPF application. During tests I noticed, that the application
I am working on a wpf application using PRISM. This is my first ever
I am trying to get Undo/Redo keyboard shortcuts working in my WPF application (I
I'm working on a new WPF application and I'm trying to stay as close
I am working on a WPF application where we are trying to build an
I am working on a WPF application using Entity Framework 4.0. When I tried
Working with a WPF application. I am very much wonderin if it is possible
I'm working on a WPF application and I'm using the MVVM pattern. I use
I'm working on a WPF application, and I'm structuring it using the MVVM pattern.
I'm working on a WPF application which should be utilizable with two monitors. In

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.