Windows default Protocol push example: how to start your default application Program File type or protocol. You can also learn how to make your application use the default application file type or Protocol
Public Sealed Partial Class Launchiliinput: Page
{
// A pointer back to the main page which is used to gain access to the input and output frames and their content.
Rootpage = Null ;
String Uritolaunch = @" Http://www.bing.com " ;
Public launchiliinput ()
{< br> initializecomponent ();
}
# region template-related code-do not remove
protected override void onnavigatedto (navigationeventargs e)
{< br> /// get a pointer to our main page
rootpage = E. parameter as rootpage;
}
protected override void onnavigatedfrom (navigationeventargs E)
{< BR >}< br> # endregion
// launch a URI.
private async void launchilibutton_click ( Object sender, routedeventargs e)
{< br> /// Create the URI to launch from a string.
var uri = New uri (uritolaunch);
// Launch the URI.
Bool Success = await windows. system. launcher. launchiliasync (URI );
If (SUCCESS)
{
Rootpage. policyuser (" Uri launched: " + URI. absoluteuri, policytype. statusmessage );
}
Else
{
Rootpage. policyuser ( " Uri launch failed. " , Policytype. errormessage );
}
}
// Launch a URI. Show a warning prompt.
Private Async Void Launchiliwithwarningbutton_click ( Object Sender, routedeventargs E)
{
// Create the URI to launch from a string.
VaR Uri = New Uri (uritolaunch );
//Configure the warning prompt.
VaROptions =NewWindows. system. launcheroptions ();
Options. treatasuntrusted =True;
// Launch the URI.
Bool Success = await windows. system. launcher. launchiliasync (Uri, options );
If (SUCCESS)
{
Rootpage. policyuser ( " Uri launched: " + URI. absoluteuri, policytype. statusmessage );
}
Else
{
Rootpage. policyuser ( " Uri launch failed. " , Policytype. errormessage );
}
}
// Launch a URI. show an open with dialog that lets the user chose the handler to use.
Private Async Void Launchiliopenwithbutton_click ( Object Sender, routedeventargs E)
{
// Create the URI to launch from a string.
VaR Uri = New Uri (uritolaunch );
// calulcate the position for the open with dialog.
// an alternative to using the point is to set the rect of the UI element that triggered the launch.
point openwithposition = getopenwithposition (launchiliopenwithbutton);
// next, configure the open with dialog.
var Options = New Windows. system. launcheroptions ();
options. displayapplicationpicker = true ;
options. UI. invocationpoint = openwithposition;
options. UI. preferredplacement = windows. UI. popups. placement. below;
// Launch the URI.
Bool Success = await windows. system. launcher. launchiliasync (Uri, options );
If (SUCCESS)
{
Rootpage. policyuser (" Uri launched: " + URI. absoluteuri, policytype. statusmessage );
}
Else
{
Rootpage. policyuser ( " Uri launch failed. " , Policytype. errormessage );
}
}
// the open with dialog shocould be displayed just under the element that triggered it.
private Windows. foundation. point getopenwithposition (frameworkelement element)
{< br> Windows. UI. XAML. media. generaltransform buttontransform = element. transformtovisual ( null );
Point desiredlocation = buttontransform. transformpoint (NewPoint ());
Desiredlocation. x = desiredlocation. x + element. actualwidth/2;
Desiredlocation. Y = desiredlocation. Y + element. actualheight;
ReturnDesiredlocation;
}
}
Complete example/files/risk/windows8/Alibaba Cloud sample. rar