Windows Phone 8.1 development: File selector Fileopenpicker

Source: Internet
Author: User

Source: http://www.bcmeng.com/fileopenpicker/

Today's little dream to share with you the file selector in Windows Phone 8.1, unlike the previous Windows Phone8, in Windows Phone8, if you want to select a photo, you can use the photo selector directly, but this in Windows phone8.1 is not available, Windows phone8.1 adds a file selector. In contrast, the file selector can choose not only photos, but also various types of files, mobile phones and SD cards can be, but also to find other devices on the network shared files, You can also browse and select the files you want on OneDrive.

The file selector is divided into two categories: Fileopenpicker and Filesavepicker. The former is used to open any file that already exists, which can create a new file or overwrite a file with the same name.

Let's see Fileopenpicker first. Common Properties:

    • Filetypefilter: File type filter, is a string type list, each element is a valid file name extension.
    • Commitbuttontext: The text displayed on the Submit button.
    • Continuationdata: Use Continuationdata to record some information to ensure that your app can get suspended information when it resumes.

Note: The Suggestedstartlocation and ViewMode properties are not valid in Windows Phone 8.1! Only in Windows 8.1.

Two ways:

    • Picksinglefileandcontinue: Select a single file and continue
    • Pickmultiplefilesandcontinue Select multiple files and continue

Let's take a look at a specific example and select a photo using the file selector:

First instantiate the Fileopenpicker object, set the file type, set the Continuationdata

Fileopenpicker openpicker = new Fileopenpicker ();            OPENPICKER.FILETYPEFILTER.ADD (". jpg");            openpicker.continuationdata["operation"] = "Image";            Openpicker.picksinglefileandcontinue ();

Then handle the onactivated event:

       protected override void OnActivated (Iactivatedeventargs args)     {            if (args is Fileopenpickercontinuationeventargs)        {        frame rootframe = Window.Current.Content as Frame;          if (!rootframe.navigate (typeof (MainPage)))        {            throw new Exception ("Failed to create target page");        }        var p = rootframe.content as MainPage;        P.filepickerevent = (Fileopenpickercontinuationeventargs) args;     }    Window.Current.Activate ();}

Finally, the returned data is processed using the file Selector's page:

 PrivateFileopenpickercontinuationeventargs _filepickereventargs =NULL;  PublicFileopenpickercontinuationeventargs filepickerevent {Get{return_filepickereventargs;} Set{_filepickereventargs=value;            Continuefileopenpicker (_filepickereventargs); }        }         Public Async voidContinuefileopenpicker (Fileopenpickercontinuationeventargs args) {if(args. continuationdata["Operation"] as string) =="Image"&& args. Files! =NULL&& args. Files.count >0) {StorageFile file= args. files[0]; Irandomaccessstream FileStream=awaitfile.                OpenAsync (Windows.Storage.FileAccessMode.Read); BitmapImage BitmapImage=NewBitmapImage ();                Bitmapimage.setsource (FileStream); Image. Source=BitmapImage; }        }

The way to use Fileopenpicker is that when you get other files, the different places are the settings for the file type and the processing of the returned data.

Windows Phone 8.1 development: File selector Fileopenpicker

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.