Startup screen of WPF application [Essence Analysis of splash screen]

Source: Internet
Author: User

 

I accidentally discovered this little trick of WPF, which is quite interesting.

I added an image to the project.

Wpf-1.JPG(10.73 K) 17:04:47

Then, set the image generation operation to splashscreen in the image attributes.

Wpf-2.JPG(13.51 K) 17:04:47

After F5 starts the program, you will find that a 0.5 second animation will appear before your main program starts. Of course, this is the default one. You can control it through the program.

Bo you: how to control it?

Debuglzq: first, let's see what happened in this process. Use reflector to decompile the PE file as follows:

From the above il code, we can intuitively see that, in fact, it first instantiates a splashscreen and then calls its show method.

If so, of course we can also write code to achieve, the msdn document on the description of the splashscreen address: http://msdn.microsoft.com/zh-tw/library/cc647682.aspx access related methods, as follows:

We can achieve this by referring to the following implementation:

First, let's change the image generation operation to "embedded resource"

Then the code is implemented. debuglzq provides the complete code as follows:

/// <Summary> /// app. interaction logic of XAML // </Summary> Public partial class app: Application {protected override void onstartup (startupeventargs e) {splashscreen S = new splashscreen ("debuglzq. jpg "); S. show (false); S. close (New timespan (0, 0, 10); base. onstartup (e );}}

Note (from msdn, please refer to the msdn document: http://msdn.microsoft.com/zh-tw/library/cc647682.aspx ):

1. The splashscreen type cannot be used in some trust cases.

2. The splashscreen type cannot be used in the XAML compiler Application Program (xbap) because these applications use different robot motion frames.

 

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.