WPF: simple gradient aero form Effect

Source: Internet
Author: User

The interface of Microsoft Office 2010 uses the gradient aero form effect, such:

 

So how to make a similar form in WPF? My answer:

 

Note:

BelowArticleThe content of Windows Vista (and later Windows systems) Exclusive API, readers need to download: Windows API code pack for Microsoft. NET Framework can run or compile the correspondingProgram.

 

First, you must reference Microsoft. windowsapicodepack. Shell. dll in Windows API code pack.

Inherit the glaswindow type in the API, as shown in the following XAML:

<Shell:GlaswindowX:Class="Wpfwindows. mainwindow"

Xmlns=Http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Xmlns:X=Http://schemas.microsoft.com/winfx/2006/xaml"

Xmlns:Shell="CLR-namespace: Microsoft. windowsapicodepack. Shell; Assembly = Microsoft. windowsapicodepack. Shell"

Loaded="Glaswindow_loaded"

Title="Mgen"Height="350"Width="525">

</Shell:Glaswindow>

 

Note that the CS file must also inherit the corresponding type:

// + Using Microsoft. windowsapicodepack. shell;

Public Partial Class Mainwindow:Glaswindow

 

In the form loaded event, first use glasswindow. the aeroglasscompositionenabled attribute determines whether the current system environment supports aero effect. If it is true, the glasswindow is called. the setaeroglasstransparency method overwrites the aero effect to the entire screen.

 

In addition, it is best to listen to the aeroglasscompositionchanged event of glasswindow, and call the setaeroglasstransparency method as needed after aero supports status change.

 

Code:

Private VoidGlasswindow_loaded (ObjectSender,RoutedeventargsE)

{

Aeroglasscompositionchanged+ =Mainwindow_aeroglasscompositionchanged;

If(Aeroglasscompositionenabled)

Setaeroglasstransparency ();

}

 

VoidMainwindow_aeroglasscompositionchanged (ObjectSender,AeroglasscompositionchangedeventargsE)

{

If(E.Glassavailable)

Setaeroglasstransparency ();

}

 

 

OK. The result is the most primitive form with full aero effect.

 

 

Next, define the gradient above. Of course, you can define it in multiple ways. I use border plus effect: first define a border, then set the background, pay attention to the need to set margin, and finally set blureffect, after adjusting the radius (through the radius attribute), everything will be OK.

 

Note: uielement. effect is available only after. NET Framework 3.5.

 

However, the control on the UI should not be added to border, otherwise it will become blurred. You need to put it in another way, as shown in the following XAML (add the control to the contentgrid below ):

<Grid>

<BorderMargin="25"Background="White">

<Border. Effect>

<BlureffectRadius="40"/>

</Border. Effect>

</Border>

<GridName="Contentgrid"

Horizontalalignment="Center"Verticalalignment="Center">

<Textblock>Hello World</Textblock>

</Grid>

</Grid>

 

 

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.