[SOURCE DOWNLOAD]
Last Stand Windows 10 (99)-association Startup: Associating specified file types, associating specified protocols
Webabcd
Introduced
Last Stand Windows 10 Association start
- Associating a specified file type
- Associating the specified protocol
Example
1. Demonstrates how to associate a specified file type (that is, open a file of the specified type with this program)
App.xaml.cs
// methods that are called when an application is activated by opening a file protected Override void onfileactivated (Fileactivatedeventargs args) { new Frame (); Rootframe.navigate (typeof(Windows10.AssociationLaunching.FileTypeAssociation), args); = Rootframe; Window.Current.Activate (); }
Associationlaunching/filetypeassociation.xaml
<Pagex:class= "Windows10.AssociationLaunching.FileTypeAssociation"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Using:Windows10.AssociationLaunching"xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"mc:ignorable= "D"> <GridName= "Grid"Background= "Transparent"> <TextBlockName= "Lblmsg"textwrapping= "Wrap"Margin= "5"> <Run>This program can open the. webabcd file type</Run> <LineBreak/> <Run>Test method: Create a new text file on the desktop, randomly lose some characters, and then change the suffix name to. WEBABCD, finally open the file, this program will display its text content</Run> </TextBlock> </Grid></Page>
Associationlaunching/filetypeassociation.xaml.cs
/* * Demonstrates how to associate a specified file type (that is, open a file of the specified type with this program) * * 1, add a "File type association" declaration in Package.appxmanifest, and make the relevant configuration * This section of this example is configured as follows * <uap:exten Sion category= "Windows.filetypeassociation" > * <uap:filetypeassociation name= ". Webabcd" > * <uap:Di Splayname> open a. webabcd file </uap:DisplayName> * <uap:Logo>Assets\StoreLogo.png</uap:Logo> * <uap:InfoTip> Open the. webabcd file with Win10 demo </uap:InfoTip> * <uap:SupportedFileTypes> * &L t;uap:filetype>.webabcd</uap:filetype> * </uap:SupportedFileTypes> * </uap:filetypeassociati on> * </uap:Extension> * 2, override void Onfileactivated (Fileactivatedeventargs args) in App.xaml.cs for related files Info * * Fileactivatedeventargs-Event parameters when activating application by opening file * files-related file information * Kind-this app is activated by type (Activationkind enumeration) * For example, if the "Open file" is activated, then this value is file * previousexecutionstate-the state before the app is activated (Applicationexecutionstate enumeration) * Than For example, if the app is running before it is activated orThis value is Running * neighboringfilesquery-Gets the adjacent file of the current file * SplashScreen-Gets the SplashScreen object for this app * User-gets activated by this a The User object for pp*/usingSystem;usingWindows.ApplicationModel.Activation;usingWindows.storage;usingWindows.ui;usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Media;usingWindows.UI.Xaml.Navigation;namespacewindows10.associationlaunching{ Public Sealed Partial classFiletypeassociation:page {PrivateFileactivatedeventargs _fileactivated; Publicfiletypeassociation () { This. InitializeComponent (); } protected Async Override voidonnavigatedto (NavigationEventArgs e) {//Get the Fileactivatedeventargs object (from App.xaml.cs)_fileactivated = E.parameter asFileactivatedeventargs; //gets the text content in the file and displays if(_fileactivated! =NULL) {grid. Background=NewSolidColorBrush (Colors.blue); Lblmsg.foreground=NewSolidColorBrush (Colors.white); Istoragefile ISF= _fileactivated.files[0] asIstoragefile; Lblmsg.text= $"The file that activates the program is "{ISF. Name} ", whose text content is: {await Fileio.readtextasync (ISF)}"; } } }}
2. Demonstrates how to associate a specified protocol (that is, using this program to process a specified protocol)
App.xaml.cs
protected Override voidOnActivated (Iactivatedeventargs args) {//when an application is activated through a protocol (see example in Associationlaunching/protocolassociation.xaml.cs) if(args. Kind = =activationkind.protocol) {Protocolactivatedeventargs Protocolargs= args asProtocolactivatedeventargs; Frame Rootframe=NewFrame (); Rootframe.navigate (typeof(Windows10.AssociationLaunching.ProtocolAssociation), Protocolargs); Window.Current.Content=Rootframe; } }
Associationlaunching/protocolassociation.xaml
<Pagex:class= "Windows10.AssociationLaunching.ProtocolAssociation"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Using:Windows10.AssociationLaunching"xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"mc:ignorable= "D"> <GridName= "Grid"Background= "Transparent"> <StackPanelMargin= "0 Ten"> <TextBlockName= "Lblmsg"Margin= "5"> <Run>This program can handle WEBABCD: protocol</Run> </TextBlock> <ButtonName= "Btnprotocol"Content= "Open Custom protocol Webabcd:data"Click= "Btnprotocol_click"Margin= "5" /> </StackPanel> </Grid></Page>
Associationlaunching/protocolassociation.xaml.cs
/** Demonstrates how to associate a specified protocol (i.e. to process a specified protocol with this program) * * 1, add a "protocol" declaration in Package.appxmanifest, and do the configuration * This section of this example is configured as follows, the protocol name must be all lowercase * <UAP: Extension category= "Windows.protocol" > * <uap:protocol name= "WEBABCD" > * <uap:logo>assets\store logo.png</uap:logo> * </uap:Protocol> * </uap:Extension> * 2, override void Onact in App.xaml.cs Ivated (Iactivatedeventargs args) to obtain the relevant protocol information * * * Protocolactivatedeventargs-event arguments when the application is activated via protocol * URI-URI of the protocol * Callerpackagefamilyname-Activate the current app's Packagefamilyname * Kind-the type of the app being activated (Activationkind enumeration) * This example is Activationkind.protocol * previousexecutionstate-Status before the app is activated (Applicationexecutionstate enumeration) * For example, if the app is stimulated This value is Running * splashscreen-Gets the SplashScreen object for this app * user-Gets the user object that activated the app*/usingSystem;usingWindows.ApplicationModel.Activation;usingWindows.system;usingWindows.ui;usingWindows.UI.Xaml;usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Media;usingWindows.UI.Xaml.Navigation;namespacewindows10.associationlaunching{ Public Sealed Partial classProtocolassociation:page {PrivateProtocolactivatedeventargs _protocolargs; Publicprotocolassociation () { This. InitializeComponent (); } protected Override voidonnavigatedto (NavigationEventArgs e) {//Get the Protocolactivatedeventargs object (from App.xaml.cs)_protocolargs = E.parameter asProtocolactivatedeventargs; //Show details of the protocol if(_protocolargs! =NULL) {grid. Background=NewSolidColorBrush (Colors.blue); Lblmsg.foreground=NewSolidColorBrush (Colors.white); Lblmsg.text="the custom protocol for the activation program is:"+_protocolargs.uri.absoluteuri; } } Private Async voidBtnprotocol_click (Objectsender, RoutedEventArgs e) { //Open the custom protocol Webabcd:dataUri uri =NewUri ("Webabcd:data"); awaitLauncher.launchuriasync (URI); //Open IE Browser, enter Webabcd:data in the Address bar, will open this program to process this Protocol } }}
Ok
[SOURCE DOWNLOAD]
Last Stand Windows 10 (99)-association Startup: Associating specified file types, associating specified protocols