Application of Multipleviews in Windows8.1

Source: Internet
Author: User



Today, let's introduce the new Applicationviewswitcher in windows8.1.

Through him we realize the multi-window processing of metro applications (which can be used in browsers, blogs, forum applications) to be fully utilized in different businesses.


So let's start with how to create multiple windows, switch


First we need to create a new view

1. Create

A new view requires a new UI thread to control, then this view needs to be created in a new Coreapplicationview UI thread

We need to call the method Coreapplication.createnewview (). Dispatcher.runasync (Note: If not in the new Coreapplicationview

Create the content that needs to be opened will not be able to toggle the direct rendering in this form)

And then in the Runasync.

var frame = new Frame ();
Frame. Navigate (typeof (XXXX), "");
Window.Current.Content = frame;


Such a form is created, and the contents of the form can be arbitrarily specified.

Then we add var viewId = Applicationview.getapplicationviewidforwindow (window);

This viewid will be used to obtain the corresponding view created by ID after switching.

2. Display/Toggle

Create a good view and get the ID so we can use

Applicationviewswitcher.tryshowasstandaloneasync method for view display this is an asynchronous method




Summary://Display another window of the application (application view) on the screen adjacent to the original window        The ID of the new window to display.        Returns the result://Returns True asynchronously if the call succeeds, otherwise false.        [Overload ("Tryshowasstandaloneasync")] [Supportedon (100859904, platform.windows)] public static iasyncoperation<bool> tryshowasstandaloneasync (int v        IEWID);     Summary://Display another window of the application (application view) on the screen adjacent to the original window        The ID of the new window to display.        Sizepreference://The preferred general size of the new window.        Returns the result://Returns True asynchronously if the call succeeds, otherwise false.        [Overload ("Tryshowasstandalonewithsizepreferenceasync")] [Supportedon (100859904, platform.windows)] public static iasyncoperation<bool> tryshowasstandaloneasync (int v        Iewid, Viewsizepreference sizepreference);        Summary://Displays another window (application view) of the application on the screen adjacent to the original window.      //  Parameters://viewId://ID of the new window to be displayed.        Sizepreference://The preferred general size of the new window.        Anchorviewid://The ID of the called (Anchor) window.        Anchorsizepreference://When the call succeeds, the new normal size of this call window is preferred.        Returns the result://Returns True asynchronously if the call succeeds, otherwise false.        [Overload ("Tryshowasstandalonewithanchorviewandsizepreferenceasync")] [Supportedon (100859904, platform.windows)] public static iasyncoperation<bool> tryshowasstandaloneasync (int v Iewid, viewsizepreference sizepreference, int anchorviewid, viewsizepreference anchorsizepreference);


These methods I do not describe the direct look at the API can be

Viewsizepreference is an enumeration

The display size of the Metro app in Windows8.1 is more diverse, from previous snaps to half, more, Minimum can accommodate different sizes of view at different resolutions

Summary://Defines a set of possible general window (application view) size preferences.    [Supportedon (100859904, Platform.windows)] [Version (100859904)] public enum Viewsizepreference {//Summary://The window size preference is not specified for the application.        The size preference will be set by Windows instead of the application, which defaults to Usehalf.        [Supportedon (100859904, Platform.windows)]        Default = 0,////Summary://Window uses 50% of the available horizontal screen pixels below.        [Supportedon (100859904, Platform.windows)]        Useless = 1,////Summary://Window uses 50% (half) of the available horizontal screen pixels.        [Supportedon (100859904, Platform.windows)]        Usehalf = 2,////Summary://Window uses more than 50% of the available horizontal screen pixels.        [Supportedon (100859904, Platform.windows)]        Usemore = 3,////Summary://The window uses the minimum horizontal pixel width (320 or 500 pixels) specified in the application manifest (for example, Package.appxmanifest).        [Supportedon (100859904, Platform.windows)]        Useminimum = 4,////Summary://The window does not have visible components.        [Supportedon (100859904, Platform.windows)]    Usenone = 5,} 

By doing this


We've made the view side-by-end display for multiple windows


Then it's much easier to switch to the new view just by switching the view through Applicationviewswitcher.switchasync with the id we just got.


3. Animations for switching between pages

Before we realized the multi-page creation and the switch function, but this kind of switch will appear very blunt, then we need to pass some animation to make his experience better.


First, you need to verify that the page has been switched, and we will perform a motion to complete the page transition.

           //Summary:         //     make the application ready to use a custom animation to convert visually between two windows. ////        Parameters:         //TOVIEWID://The     ID of the window from which the application was switched. ////   fromviewid:/        /The     ID of the window to which the application is being toggled. ////   options:        //     Specify an enumeration value for the view toggle behavior. /////        Returns the result:         //returns     true asynchronously if the call succeeds, otherwise returns false.        [Supportedon (100859904, platform.windows)] public        static iasyncoperation<bool> Prepareforcustomanimatedswitchasync (int toviewid, int fromviewid, applicationviewswitchingoptions options);


But when prepare returns false, it indicates that the page is not ready.

Then we can execute a section of storyboard on the current page before this storyboard execute and then call switch

At the same time the target page can also prepare a animation to show

Code

http://download.csdn.net/detail/wangrenzhu2011/7271485


The Animationdescription usage used in sample is described in the next 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.