Preset Control styles for WPF applications, such as Aero, Luna, Royal, and Classic

Source: Internet
Author: User
WPF presets include Aero, Classic, Luna, and Royal themes. The WPF program determines the control style used by the WPF program based on the Windows theme, and when the Windows theme is not Aero, Luna, or Royal, if it is another topic, WPF will adopt an ugly Classic topic. How can I make the WPF program use the specified topic?

The following example shows how to set the topic as Aero:
Add the reference PresentationFramework. Aero. dll to the WPF project and add it to the Resources of the program. <Application. Resources>
<ResourceDictionary Source = "/PresentationFramework. Aero, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35; component/themes/aero. normalcolor. xaml"/>
</Application. Resources>

This is equivalent to referencing the spatial style code in the PresentationFramework. Aero assembly to the current program.
Note: The project must reference the Assembly corresponding to the topic, such as PresentationFramework. aero. dll, PresentationFramework. royale. dll and so on. They can be found in "Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.0" or GAC.
The above XAML code can also be replaced by the corresponding C # code, such as adding code to the Startup event handler of the Application: Protected override void OnStartup (StartupEventArgs e)
{
Base. OnStartup (e );
Uri aero = new Uri ("/PresentationFramework. Aero, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = token; component/themes/aero. normalcolor. xaml", UriKind. Relative );
Resources. MergedDictionaries. Add (Application. LoadComponent (aero) as ResourceDictionary );
}

Of course, you can also add this ResourceDictionary to the Resources of the Window, so that this topic will only be used in this Window.

The method to specify other topics is similar, that is, reference related dll and add Resources.
The Aero themes in WPF are exactly the same style as those in Windows Vista, including the animation effects when MouseEnter is used, the following is an Aero-themed WPF program running on Windows 2003 with Luna Element 4 enabled:

However, the Aero topic in WPF does not have glass effect in non-Windows Vista systems. It is not something that GDI can do ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.