Selector: Custom file Selection window, custom file Save window
Introduced
Re-imagine the Windows 8 Store Apps Selector
Fileopenpickerui-Custom File Open Selector
Filesavepickerui-Custom File Save Selector
Example
1, develop a custom file Selection window. Note: If you need to activate a custom File Selection window, select the corresponding Provider in the upper left corner of the pop-up selector window
Picker/myopenpicker.xaml
<page
x:class= "XamlDemo.Picker.MyOpenPicker"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "
xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:local=" using: Xamldemo.picker "
xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "
mc:ignorable=" D ">
<grid background=" Transparent ">
<stackpanel margin=" 0 0 0 ">
<textblock name=" lblmsg "fontsize=" 14.667 "/>
<button name= "btnpicklocalfile" content= "Select a local file" click= "Btnpicklocalfile_click_1" margin= "0 0 0"/>< C12/><button name= "Btnpickremotefile" content= "Select a remote File" click= "Btnpickremotefile_click_1" Margin= "0 0 0"/>< c13/></stackpanel>
</Grid>
</Page>
Picker/myopenpicker.xaml.cs
* * Demonstrates how to develop a custom file open picker * * 1, add a "File Open selector" declaration in Package.appxmanifest, and make a related configuration * 2, override void Onfileo in App.xaml.cs Penpickeractivated (Fileopenpickeractivatedeventargs args), if the app is activated by a file open selector, you can get information about it here * * Fileopenpickeractivatedeventargs-Event parameter * Fileopenpickerui-Gets the Fileopenpickerui object * When activating the application through the file open selector * Previou Sexecutionstate, Kind, SplashScreen-the various event parameters that activate the app basically have these properties, and they don't say much. * Fileopenpickerui-Custom File Open Picker Help class * Allowedfiletypes-allowed file types, read Only * SelectionMode-selection mode (Fileselectionmode.single or fileselectionmode.multiple) * T Itle-Title * canaddfile (istoragefile file) to be displayed on the custom file open Picker-can add the specified file to the selected file list * AddFile (string ID, ISTORAGEF Ile file-adds files to the selected file list and specifies the ID * containsfile (String id)-Select whether the file list contains the specified ID * removefile (string ID)-based on the ID from the selected
Delete the corresponding file in the list of files * fileremoved-event triggered when a file is deleted from the selected file list * Closing-event triggered when the user closes the custom file open picker/using System;
Using Windows.applicationmodel; Using Windows.applicaTionmodel.activation;
Using Windows.storage;
Using Windows.Storage.Pickers.Provider;
Using Windows.Storage.Provider;
Using Windows.Storage.Streams;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation; Namespace Xamldemo.picker {public sealed partial class Myopenpicker:page {private Fileopenpickerui _fi
Leopenpickerui; Public Myopenpicker () {this.
InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {//Get Fileopenpickerui Pair
like var args = (Fileopenpickeractivatedeventargs) e.parameter; _fileopenpickerui = args.
Fileopenpickerui;
_fileopenpickerui.title = "Custom File open selector";
_fileopenpickerui.closing + = _fileopenpickerui_closing;
_fileopenpickerui.fileremoved + = _fileopenpickerui_fileremoved;
} protected override void Onnavigatedfrom (NavigationEventArgs e) {///_fileopenpickerui.closing-= _fileopenpickerui_closing;
_fileopenpickerui.fileremoved-= _fileopenpickerui_fileremoved; //Select a local file private async void Btnpicklocalfile_click_1 (object sender, Windows.UI.Xaml.RoutedEventA
RGS e) {* * Note: * 1, the extension of the selected file must match the definition in Fileopenpicker.filetypefilter * 2, if the selection of files through Knownfolders.documentslibrary, in addition to the package.appxmanifest to select the corresponding "library" function, but also in the package.appxmanifest "file Add support for corresponding extension in type Association declaration * * Storagefile file = await Package.Current.InstalledLocation.GetFileA
Sync (@ "assets\logo.png");
Addfileresult result = _fileopenpickerui.addfile ("myFile", file); Lblmsg.text = "Selected files:" + file.
Name;
Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Addfileresult:" + result.
ToString (); //Select a remote file private async void BtnpickremotEfile_click_1 (object sender, Windows.UI.Xaml.RoutedEventArgs e) {uri uri = new Uri ("HTTP://IMAGES.CNB
Logs.com/mvpteam.gif ", Urikind.absolute); The extension must match the definition in fileopenpicker.filetypefilter storagefile file = await Storagefile.createstreamedfilefromurias
Ync ("Mvp.gif", Uri, Randomaccessstreamreference.createfromuri (URI));
Addfileresult result = _fileopenpickerui.addfile ("myFile", file); Lblmsg.text = "Selected files:" + file.
Name;
Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Addfileresult:" + result.
ToString (); }
}
}
Determine if the program is activated by a file open selector, override void Onfileopenpickeractivated (Fileopenpickeractivatedeventargs args) in App.xaml.cs
The
method that is invoked when the selector activates the application through a file
protected override void Onfileopenpickeractivated ( Fileopenpickeractivatedeventargs args)
{
var rootframe = new Frame ();
Rootframe.navigate (typeof (XamlDemo.Picker.MyOpenPicker), args);
Window.Current.Content = Rootframe;
Window.Current.Activate ();
}
2, the development of a custom file save window. Note: If you need to activate a custom file Save window, select the corresponding Provider in the upper left corner of the pop-up selector window
Picker/mysavepicker.xaml
<page
x:class= "XamlDemo.Picker.MySavePicker"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "
xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:local=" using: Xamldemo.picker "
xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "
mc:ignorable=" D ">
<grid background=" Transparent ">
<stackpanel margin=" 0 0 0 ">
<textblock name=" lblmsg "fontsize=" 14.667 "/>
</StackPanel>
</Grid>
</Page>