开发者

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开发者_如何学Go 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜