Changing The MahApps Metro Theme - wpf

I know that the MahApps metro theme comes with "themes" (colour sets), but I don't know how to change them from the default settings in my WPF application.
I have followed the beginners tutorial at MahApps.Metro Documentation (including adding the resource libraries at the top of the page), but it makes no mention about changing the theme.
The component/Styles/Colours.xaml file has the comment "from the cosmopolitan theme pack", which may be a helpful clue to someone better versed in WPF design than me.
I'm talking about an app-wide theme change, not an individual control.

If you want to change the default colour scheme, just change which colour resource file is loaded.
from Blue:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
to Red:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Red.xaml" />
You can also change programatically (once you've loaded every colour resource file) using ThemeManager.ChangeTheme().

Related

Browse MahApps resources

I started with MahApps and would like to know how to browse MahApps resources in general similar to Object catalog in Visual Studio. Like I am able to read all available Icons in the the icons.xaml in resource folder, I would like to be able to do so, for any DynamicResource such as AccentColorBrush.
If this is not possible, how am I supposed to know about my possibilities and the capabilities of MahApps since XAML does not know suggestions?
Take a look here: https://mahapps.com/guides/styles.html
Under the Creating Custom Accents and Themes chapter (about the end of the page), you can see all possible x:Key of colors and brushes according with the selected theme in App.xaml resources.

Mahapps.Metro dark theme not showing in designer

I am using MahApps.Metro version 1.2.0.0. I have set my theme to a Dark theme. This works fine when I run the application but still shows the light theme in my designer.
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
Thoughts on what is causing this issue?
I found that in XAML designer:
The window title bar is never styled
After restarting Visual Studio, the components seem to be styled...
...except for MetroWindow's background, which shows as white.
So, many components are white-on-white (invisible!) in the designer. I've been working around it, as follows.
For MetroWindows, I set the background of each to reference the theme color:
<Controls:MetroWindow
....
Background="{DynamicResource WindowBackgroundBrush}">
For user controls and pages, rather than set the background on every one, you can leave it transparent and set the designer to have a dark background. Then they show up well enough for designing:
It's a bodge, but its what I've been working with.

Theme in MergedDictionary in Silverlight not working design time

Ok, this is driving me crazy now. I have a Silverlight 5 project. Not long ago we decided to theme our project, just to make it pop more. I found a theming implementation and went ahead.
First i used the .Theming namespace from the Silverlight Toolkit. I used the explicitly build theme.dll's. There was a shortcoming with this though, that i didnt have the ability to customize the theme. So i decided to just use the theme.xaml instead, and implement it by using <MergedDictionaries>.
The problem with this approach though, is that i lost the ability to see the theme in design time. In runtime it works fine. But that's just not good enough, when i wan't to customize the theme.
I implemented the theme by using merged dictionaries in App.Xaml like so
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/eCP;component/Themes/WhistlerBlue.xaml"/>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="ViewModelLocator"/>
</ResourceDictionary>
</Application.Resources>
If i put the same blok in my MainPage, the theme instantly turns on in design time there. But it shouldnt be necessary to do it on every Silverlight page?
So in short: If i implement the theme in with MergedDictionaries in App.xaml it does not work in design time. If i do it on a specific page, it does work.
Funny thing though, if i open my project in Expression Blend, it works fine in design time.
My first notion is, that something is messing with my visual studio 2010 SP1. Maybe something in a hidden project file or something, but i don't know.
Anyone able to help?

How do I access to the resources in the Fluent Ribbon Control Suite?

I'm developing a WPF application that uses the Fluent Ribbon Control Suite and i'd like to use its 'themes' in the rest of the application.
Specifically, when you choose to use the Blue theme
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Blue.xaml" />
I would like to use some of the colours inside that file, to style other interface elements (buttons, popups etc).
Any idea how I might do this?
You can try this, but it's not ideal…
Downloaded the Source Code from here and open it up in Blend.
Using the Resources tab, browse the different ResourceDictionary file (ColorsBlue.xaml, Button.xaml etc.)
Make a note of the resource keys for the resources you want.
In your original application add the styles/colours etc you want.
Now whenever you change the theme (Blue/Black/Silver etc) it will automatically change the background colour of your controls!
Hope that helps.

How can I load a WPF theme?

My understanding of the difference between a WPF theme and a WPF skin is the following:
A WPF skin is a set of resources loaded by an application.
A WPF theme is a set of resources handled by the OS.
To load a skin, I can just call Application.Current.Resources.MergedDictionaries.Add (mySkin);
However, I don't see any way to load a theme.
Is this documented or available?
Should I access the System.Windows.SystemResources internal class?
You can load them as a ResourceDictionary:
<Window
x:Class=”TestProject.Window1?
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>
<Window.Resources>
<ResourceDictionary
Source=”/presentationframework.aero;component/themes/aero.normalcolor.xaml” />
</Window.Resources>
</Window>
Note: You would need to have a reference to the PresentationFramework.Aero.dll.
There's quite a subtle difference between Skins and Themes, and the reason why you're having problems with what you're trying to do might stem from this:
In WPF, a theming and skinning takes
on slight variations to their
meanings. Theming refers to
controlling the look and consistency
of an application UI to match the
operating system. For example, a WPF
application can be themed for the
Windows Aero theme or the Windows
Classic Theme. Skinning refers to
changing the application's appearance.
In other words, applying or letting
the user pick a skin to change the
look and feel of the application.
Robby Ingrebertsen, while working on
the WPF team, simplifies it as
follows:
Around here, we generally say that "theming" refers to the system theme
and "skinning" refers to changes to a specific app. This has helped to
clarify our internal communication
From here
So essentially, if you want your app to look like one of the Windows themes,ie the current windows theme - you don't have to set any styles in your app and it'll chose a pre-defined XAML skin that resembles it automatically. But, if you want to style your application, you make a skin for the app as you're doing.
As far as loading the Windows themes, this answer might help
(Answering my own question)
The way to load a resource dictionary as a theme is to add it to the list of merged dictionaries of the generic.xaml resource dictionary.

Resources