Browse MahApps resources - wpf

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.

Related

Custom Control into an Window application in WPF

the title isn't really meaningfull... sorry for this.I'll try to explain my issue.
I have a bigger project in which i'm trying to implement a new WPF window which contains some custom controls. Going deeper this window should looks like, let's say, a calculator. This calculators has many keys buttons which are "custom controls" inherited from Controls, and their style are defined in Generic.xaml.
When i try to debug it, the custom controls (the key buttons) don't appear into the calculator window.
I think it's due to something wrong with the Generic.xaml file.
Can someone give me a hint ???
Thanks in advance
Paolo
A couple of suggestions:
download Snoop (it's free), it examines your Visual tree at run time and helps to see if controls are there, if the style making them invisible, etc.
remove the styles, run your project - do controls appear? then it's your styles!
do you have nameless/key-less styles that target buttons, other simple/out-of-the-box control? Then remove them too, if they are the ones affecting your controls, then consider changing them, or applying styles to your controls so they stop inheriting from those defaults.
I've searched a lot on the net and finally i've got the solution following the answer of this discussion wpf-resource-not-loading-from-generic. The clue is to add into the AssemblyInfo.cs these lines of code:
[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
//where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly
//where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Maybe this could be useful for someone in the future... :-)
Regards,
Paolo

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.

How do WPF themes get loaded?

WPF controls get their default styles, colors and brushes from a theme (Usually, in PresentationFramework.Aero.dll).
What piece of loads this assembly? And where are the resource dictionary stored?
I have my own WPF custom themes and load them in the Application.Current.Resources.MergedDictionary.
However, this does not work if the WPF themed control is hosted in Windows Forms since Application.Current is null.
Is there a way to do something similar to what WPF does? If so, what is it?
You cannot use the WPF themes in Winforms because they are two different technologies. There isn't a similar theme mechanism in Winforms natively. You can use third-party controls that support themes in Winforms. The most notable of these are the tools from Infragistics and Telerik.
Bottom line answer is no, there isn't.
Can you try just adding the theme to the control instead of the Application?
control.Resources.MergedDictionaries.Clear();
control.Resources.MergedDictionaries.Add(resourceDictionary);
(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.
There is no other way to load a resource dictionary as a theme.
This works fine when used from WinForms

Where to find Generic.xaml for native WPF controls?

Where to find Generic.xaml (or other code with the default look) for native WPF controls such as Button, CheckBox, TextBox, etc?
In Silverlight (and I know that your question is about WPF) this information is more accessible than in WPF. You can get this information from any of these sources:
Control Styles and Templates on MSDN.
You can look at the resources of the relevant Silverlight assembly and extract the themes/generic.xaml embedded in a resource. I use Reflector to do this.
You can extract the control template of a specific control using a tool. I use Expression Blend to do this. This also works for WPF.
Unfortunately the XAML for native controls is not directly available as a file. You need to use a program for peeking into the WPF assemblies and extracting that info. I personally have used the Mole for Visual Studio tool, which has done the job very well. It integrates as a debugger-visualiser, which is quite handy.

Resources