WPF: Perfect custom MeaagseBox animation bounce background blur flat, wpfmeaagsebox

Source: Internet
Author: User

WPF: Perfect custom MeaagseBox animation bounce background blur flat, wpfmeaagsebox

I don't know why. The MeaageBox style of WPF still stays in the Win 2000 style...

 

A long time ago, I wanted to encapsulate a MessageBox myself, but it was only a simple package and not very universal. This is the end.

The similarity between the method and the MessageBox method is more than 90%. In addition, in 10%, we added some more practical things.

Okay, I don't want to talk much about it.

The following elements are frequently used in MessageBox:

1. MessageButton: for future extension convenience, the native MessageButton enumeration is not used here, but a custom enumeration is used:

/// <Summary> /// button type displayed in CMessageBox /// </summary> public enum CMessageBoxButton {OK = 0, OKCancel = 1, YesNO = 2, yesNoCancel = 3}

2. MessageBoxImage. Due to the convenience of future extension, the native MessageBoxImage enumeration is not used here, but a custom enumeration is used:

/// <Summary> /// icon type displayed in CMessageBox /// </summary> public enum CMessageBoxImage {None = 0, Error = 1, Question = 2, warning = 3}CMessageBoxImage

3. MessageBoxResult. For future extension convenience, the native MessageBoxResult enumeration is not used here, but a custom enumeration is used:

/// <Summary> /// return value of the message box /// </summary> public enum CMessageBoxResult {// The user closes the message window None = 0, // The user clicks OK = 1, // the user clicks the Cancel button Cancel = 2, // the user clicks Yes = 3, // the user clicks No = 4}CMessageBoxResult

4. CMessageBoxDefaultButton, Windows MessageBox does not have this enumeration. By using this enumeration, you can highlight the buttons on the MessageBox (for example, the MessageBox of YesNo can highlight Yes). There are many such application scenarios.

/// <Summary> /// key display button of the message /// </summary> public enum CMessageBoxDefaultButton {None = 0, OK = 1, Cancel = 2, yes = 3, No = 4}CMessageBoxDefaultButton

The common enumeration methods of MessageBox are 1, 2, and 3. After the enumeration is defined, the Show method can be used to simulate Windows MessageBox:

/// <Summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> public static CMessageBoxResult Show (string cmessageBoxText) /// <summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> /// <param name = "caption"> Message Title </param> public static CMessageBoxResult Show (string cmessageBoxText, string caption) /// <summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> /// <param name = "CMessageBoxButton"> message box button </param> public static CMessageBoxResult Show (string cmessageBoxText, CMessageBoxButton) /// <summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> /// <param name = "caption"> Message Title </param> /// <param name = "CMessageBoxButton"> message box button </param> public static CMessageBoxResult Show (string cmessageBoxText, string caption, CMessageBoxButton) /// <summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> /// <param name = "caption"> Message Title </param> /// <param name = "CMessageBoxButton"> message box button </param> /// <param name = "CMessageBoxImage "> message box icon </param> /// <returns> </returns> public static CMessageBoxResult Show (string cmessageBoxText, string caption, CMessageBoxButton, CMessageBoxImage) /// <summary> /// display the message box /// </summary> /// <param name = "cmessageBoxText"> message content </param> /// <param name = "caption"> Message Title </param> /// <param name = "CMessageBoxButton"> message box button </param> /// <param name = "CMessageBoxImage "> message box icon </param> /// <param name =" CMessageBoxDefaultButton "> default message box button </param> /// <returns> </returns> public static CMessageBoxResult Show (string cmessageBoxText, string caption, CMessageBoxButton, CMessageBoxImage, CMessageBoxDefaultButton)

Then you need to add a Window, which is the main interface of the custom MessageBox. There is nothing to say about this interface. If you need code, you can download it at the final download link.

It is worth mentioning that a startup animation is added to the MessageBox In the Loaded Trriger, which is a scaling animation with a rebound effect.

 

Then we need to implement fuzzy effects without MessageBox. Of course, the blur effect does not mean that MessageBox is blurred, but its parent form is blurred when MessageBox is popped up.

Fuzzy effects:

            BlurEffect effect = new BlurEffect();            effect.Radius = 6;            effect.KernelType = KernelType.Gaussian;            Application.Current.Windows[0].Effect = effect;

The following figure shows a GIF simulation with a DOT card:

The real effect is much better than it...

 

 

 

Source code download: http://download.csdn.net/detail/lyclovezmy/7635001

 




Related Article

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.