I have the job to redesign one of our applications. The base mechanism we use, is simple. We got a host application (wpf) with a tab control, the application modules are class libraries with wpf user controls (separate project). the user controls are loaded into the tab control of the host...
Our idea is like that: we would like to style the host with MahApps BaseBlack theme and the modules should be in BaseLight Theme style...
Running this setup causes the modules to be styled with the hosts theme ?
What can I do to make the modules running with a separate theme ?
Many thanks - I'm new to wpf and happy to get some help :-)
Peter
I guess you always have the option of specifying the style local to your MainWindow and to each individual usercontrol instead of just declaring your style for mahapps for your entire application in the app.xaml.
MainWindow
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Each Usercontrol
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Related
Regarding this question and Marc's answer, I find this solution perfect, but I have trouble organizing my solution to make it functional.
How can I create a styling project that contains only XAML and reference to sub XAML, and how can I use it elsewhere in my solution? What is the visual studio project used by Marc in his answer to create the styling project?
Thank you,
B
You could create a WPF User Control Library in Visual Studio and add ResourceDictionary items where you define your XAML resources to it.
You then add a reference to this WPF User Control Library from your WPF Application project (Project->Add Reference in Visual Studio) and merge the resource dictionaries that are defined in the library in the App.xaml of your application:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WpfUserControlLibrary1;component/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Replace "WpfUserControlLibrary1" with the name of the WPF User Control Library and "Dictionary1" with the name of the ResourceDictionary that you added to this project.
I've got a main project that is producing my executable. In the App.xaml I am defining some base styles.
Now I want to use this styles in other projects respectively in other libraries (dlls).
I read all the questions about this problems here in stackoverflow, but it doesn't work for me.
Could it be, that I get this problems, because I want to use the styles in the libraries referenced by the main project?
Thanks, Alex
You should move these styles to a separate Resource Dictionary which could be used by multiple projects/applications.
Create the resource dictionary and add it to your project and then reference it in your App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="\shared\MyResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Create a new WPF User Control Library, add a ResourceDictionary to this project and move your styles from App.xaml to this ResourceDictionary. Then you add a reference (Project->Add Reference in Visual Studio) to this new project from your WPF application and any other application in which you want to use these styles and merge the ResourceDictionary into the App.xaml:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WpfControlLibrary1;component/ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application>
Obviously you need to change "WpfControlLibrary1" and "ResourceDictionary1" to the actual names of the new project and ResourceDictionary respectively.
This way you have moved the common styles to a stand-alone assembly that you could use in many different applications.
Hello I'm trying to apply a theme to Fluent Ribbon but unfortunately it doesn't work. But what interesting in the visual studio designer everything works. Here is the code with I try to do it, and one more question. How to disable full screen mode in the main window?
<Application x:Class="WLDA.Server.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Windows8/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Test App
This might be caused by the Fluent Ribbon styles being automatically added by Orchestra for you (and they default to Office 2013).
One solution could be to remove the existing dictionary from Application.Current.Resources.MergedDictionaries and add the Windows 8 instead.
You could use the Orchestra repository (with examples) to test if this works.
we are using Infragistics WPF controls (e.g. xamDataGrid, xamDockManager etc), and we will be using the Infragistics Office 2007 Blue theme which these controls support.
We also want to style the rest of the application (i.e. standard WPF controls) using the same Office 2007 Blue style.
What's the best approach? Are there Office 2007 themes/skins that we can download or purchase? Can we use anything from the Infragistics download?
I know this is an old question, but maybe little update can be helpful for anyone that stumbles upon this. It is working in current version of Infragistics. Resource in App.xaml in enough. Sources point to folder in solution that contains files from Infragistics themes (usually something like C:\Program Files (x86)\Infragistics\2015.1\WPF\Themes).
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Theme/Styles.Shared.xaml" />
<ResourceDictionary Source="/Theme/Styles.WPF.xaml" />
<ResourceDictionary Source="/Theme/Theme.Colors.xaml" />
<ResourceDictionary Source="/Theme/IG.MSControls.Core.Implicit.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
IIRC for winforms infragistics allow you to use the app stylist to be able to theme the standard controls.
Just had a quick look on the forums and it doesn't look like it can be done for WPF.
How to apply themes to non-Infragistics controls
I'm trying to learn more about WPF. I ran through an online tutorial that created a button and then created a template to be applied to additional buttons. The problem is this template is in the Window.xaml and I can only access the template from within that application. How do I make the template more globablly available? I'm thinking of some way to reference the xaml like you can reference an assembly from a different project or solution.
You can use "resource dictionaries" which you reference in your App.xaml like this (Expression Blend does it automatically):
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
How to reference a resource from another assembly, use pack URI syntax. This link covers it as well.