"Win 10 Application Development" method for full-screen playback

Source: Internet
Author: User

Original: "Win 10 application Development" to achieve full-screen playback method

One would ask, did the previous MediaElement control have an existing row of action buttons? And you can go directly to full screen playback. Yes, we know that the previous store app was running in full-screen mode, so long as the MediaElement control fills the entire window, it's equal to full-screen playback, but the Win10 app is windowed, When you set the Isfullwindow property of the MediaElement control to True, this is the case:

From the above view, the MediaElement control just covers the entire window, and does not implement fullscreen. Is there a way to make it play in full screen?

Since the old week to write a blog, of course, there is. In fact, the SDK exposes an API that allows applications to be full-screen, just like the win8/8.1 application. Under the Windows.UI.ViewManagement namespace, there are types associated with application view management, one of which is called Applicationview, and the class, like its name, knows what it's about, yes, the Admin app view.

The Applicationview class has two ways to compare fun:

Tryenterfullscreenmode: Guess what it's used for?

Exitfullscreenmode: Exit full-screen mode after calling.

OK, knowing that there is such a guy, there is probably a thought: when the MediaElement control fills the window, call the Tryenterfullscreenmode method, full screen; Use the Exitfullscreenmode method to exit the full screen when the MediaElement control is restored. That

When Mediaelement.isfullwindow = = True, Tryenterfullscreenmode;

When Mediaelement.isfullwindow = = False, Exitfullscreenmode.

The principle is this, as to how to achieve the law, the beholder, you like how to do all the line, to achieve the desired effect is OK.

The old-week approach is done through a two-way binding between dependency properties.

First declare a dependency property IsFullScreen on the page class that contains the MediaElement control or on the custom container class:

        Private Static ReadOnlyDependencyProperty Isfullscreenproperty = Dependencyproperty.register ("IsFullScreen",typeof(BOOL),typeof(MainPage),NewPropertyMetadata (false,NewPropertychangedcallback (onisfullscreenpropertychanged));  Public BOOLIsFullScreen {Get{return(BOOL) GetValue (Isfullscreenproperty); }            Set{SetValue (isfullscreenproperty, value);} }        Private Static voidonisfullscreenpropertychanged (DependencyObject D, DependencyPropertyChangedEventArgs e) {... }

The Onisfullscreenpropertychanged method is used to respond to a property change, in which the value of the property is judged, and if true, the full screen is entered, otherwise the full screen is exited.

        Private Static void onisfullscreenpropertychanged (DependencyObject D, DependencyPropertyChangedEventArgs e)        {            bool b = (bool) E.newvalue;             var appview = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView ();             if (b)            {                appview.tryenterfullscreenmode ();            }             Else             {                appview.exitfullscreenmode ();            }        }

property is done, how does it relate to the Isfullwindow property of MediaElement? The Isfullwindow property is also a dependency property, and a two-way binding can be done directly between dependency properties, which is why you just defined the IsFullScreen property as a dependency property.

In a XAML document, simply bind the IsFullScreen to Isfullwindow.

        < MediaElement ...  Isfullwindow= "{Binding isfullscreen, elementname=thepage, Mode=twoway, updatesourcetrigger= PropertyChanged}"/>

Thepage is the name of the current page instance.

< Page     x:class = "Fullscreenapp.mainpage"     ... x:name= "thepage">

Because just now my isfullscreen attribute is defined in the MainPage page class.

This way, as long as the Isfullwindow property changes, the IsFullScreen property is changed, and then the full screen can be entered/exited.

Let's take a look at the results.

Just run, not full screen, effects such as:

Then click the Full Screen button of the MediaElement control to go to full screen playback, such as:

What, you got the effect?

Sample source code Download: Http://files.cnblogs.com/files/tcjiaan/FullScreenApp.zip

"Win 10 Application Development" method for full-screen playback

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.