How to include and use Themes in wpf application - wpf

I have to include themes to my wpf application and use them for look and feel of the windows(.xaml) and controls.
i tried to include the theme files like below code but it is throwing error.
<Application.Resources>
<ResourceDictionary Source="\Themes\BureauBlack.xaml"/>
How to assign source path of a theme file which is assign Build action as Resource

Try to use MergedDictionaries:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic_UI/BlueColors.xaml"/>
<ResourceDictionary Source="Generic_UI/KStyles.xaml"/>
<ResourceDictionary Source="Generic_UI/KButtons.xaml"/>
<ResourceDictionary Source="Generic_UI/KWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Related

ResourceDictionary administration

The main WPF project has resources defined in App.xaml.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Views;component/Themes/Standard.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Here Views is another project which contains all kinds of UserControls.
This works all right, except that in the UserControls xaml the styles of Standard.xaml are not recognized because in this project App.xaml is not loaded.
So, compile time warnings like Resource cannot be resolved are shown.
It can be fixed by adding
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Views;component/Themes/Standard.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
to all UserControl files, but I would like to add this only one time somewhere in this project that doesn't contain App.xaml.
I can also ignore the warnings of course.
Inheritance for UserControl is when I understand correctly only possibe in a .cs file, not with a .xaml file.
Any other suggestions?

Import multiple resource files in app.xaml wpf

[Running on Windows 8]
I know how to import a single one, like this:
<Application.Resources>
<ResourceDictionary Source="Styles\MyCombobox.xaml"/>
</Application.Resources>
but I want something like this:
<Application.Resources>
<ResourceDictionary Source="Styles\X.xaml"/>
<ResourceDictionary Source="Styles\Y.xaml"/>
<ResourceDictionary Source="Styles\Z.xaml"/>
</Application.Resources>
I get:
The property Resource can only be set once!
You should merge that dictionaries.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles\X.xaml"/>
<ResourceDictionary Source="Styles\Y.xaml"/>
<ResourceDictionary Source="Styles\Z.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
More in documentation
UPDATE
Of course, you should wrap property usage in ResourceDictionary tag.

XAML ResourceDictionary same-assembly reference

I'm developing a WPF control library, and I need to reference a resource dictionary defined in the same assembly.
I managed to get it working with a separate-assembly reference.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MyLocalAssembly;component/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
While with a same-assembly reference it doesn't work, and raises an exception ("Cannot locate resource 'Foo.xaml'.") at load time. Note that in the designer everything works fine, no matter which method I use.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Don't use absolute path for the resource dictionary. Simply use relative path reference.
For example,
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="folder/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

How to merge resource files from other assemblies in Silverlight / wp7

In my app i need to merge the resource file from an external assembly. Is it possible to do so? If the answer is yes please guide me to resolve this issue .
Try this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/StyleResource.Styless;component/ButtonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Referencing Themes in a dll in WPF

I am using an opensource wpf TreeListView control. The control is a library project with a themes folder in it containing some xaml theme files. In my wpf project, I have got a reference to the control dll and I would like to know how to reference the dll themes in app.xaml. I tried doing something like this but it throws exception saying can't find the treelistview assembly
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
<ResourceDictionary Source="/TreeListView;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary>
</Application.Resources>
At the moment I have to copy all the theme files in my wpf project locally to make it work like this.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
<ResourceDictionary Source="themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Is there a way to reference theme files directly in the TreeListView dll like referencing default themes.
Awaiting
Nabeel
I figure it out myself, I was using the wrong assembly file name.

Resources