Resource Allocation to WPF Window (.xaml File)

Posted by Tushar under WPF on 3/3/2010 | Views : 3159 | Status : [Member] | Replies : 2
Hi friends

In My WPF application I allocate the Default Theme (say BlueTheme.xaml)
Here is code that i write in Application_startUp Methods.

string packUri = @"/Customize Themes;component/Resources/BlueTheme.xaml";
Uri url = new Uri(packUri, UriKind.Relative);
ResourceDictionary rd = Application.LoadComponent(url) as ResourceDictionary;
Application.Current.Resources = rd;

so when project is compile the BlueTheme.xaml is allocated to WPF window as Resource.
So Blue Theme is Apply to the WPF controls.

Now I create a Color Picker and change the color of different Property of WPF controls
that will update on the BlueTheme.XAML file
So when I select new color of (say Button Background color) then the BlueTheme.xaml file will update the new color
and that will reflect On the current Window Automatically....

Means that I have .xaml file that allready allocate to the WPF window As Resource
But at the Runtime I Update or Overwrite the .xaml file
after Whterver change I done in .Xaml file that will reflect the Current WPF window. How ?
So what so I do for that .....?
Plaese help me ....

Is it Possible ?
Give Good Link or Blog..

Here My BlueTheme.xaml

<ResourceDictionary xmlns=""
<Style TargetType="{x:Type Button}" >
<Setter Property="Background" Value="#C3C3EE"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="Foreground" Value="Black"/>
</ResourceDictionary >

Advance Thanks
Have Nice Time


Posted by: Abhi2434 on: 3/3/2010 [Member] [Microsoft_MVP] [MVP] Silver

The main objective of Resource is to store a theme in compiled assemblies and you can invoke it when it is required.

If you want to customise, why dont you store the values in database and dynamically change them when ResourceDictionary objects are created ?

Actually resources are compiled within the assembly so it is not a good idea to change. Rather you can create your resource in database which will be easier to handle in this regard.

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kunal2383 on: 3/9/2010 [Member] Starter

I am strongly agree with Abhishek. It will be better in your case, if you dynamically assign & load the values to & from DataBase instead of XAML.

Thanks & Regards,
Kunal Chowdhury | |

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response