Interaction with the Silverlight Browser: Install the Silverlight program locally

Source: Internet
Author: User

Overview

Application. InstallMethod
Try to install the applicationProgramSo that the application can run outside the browser.
This method can only work in the event handler of the event initiated by the user, and can work normally only when the Application List is correctly configured to enable external browser support.
If these conditions are not met, this method returns false and the installation dialog box is not displayed.
If the application requires a higher level of trust, this method returns true before the installation dialog box is displayed.

Application. installstatechangedEvent
Occurs when the value of the installstate attribute is changed.

Application. isrunningoutofbrowserAttribute
Gets a value indicating whether the application is started out of the browser.

InstallstateEnumeration
Notinstalled has not installed the application to run outside the browser.
Installing is installing this application to run outside the browser.
Installed has installed the application to run outside the browser.
Installfailed cannot install this application to run outside the browser.

Effect

Run the program because the Silverlight program is not installed locally.

Click the installer to display

The shortcut appears on the desktop ..

Double-click the shortcut to open the program...

Running the original web program ....

XAMLCode:

   <  Grid  X: Name  = "Layoutroot" Background  = "White"  >  
<! -- Here there are three grids.
When the program runs from a browser and is not installed locally, ibnotinstalledexperience is displayed
When the program runs from a browser and has been installed locally, ibinstalledexperience is displayed
When the program runs locally, oobexperience is displayed
-->
< Grid X: Name = "Ibnotinstalledexperience" Visibility = "Collapsed" >
< Button X: Name = "Installbutton"
Height = "100"
Width = "400"
Fontsize = "30"
Horizontalalignment = "Center"
Verticalalignment = "Center"
Content = "Not installed yet... Please install" />
</ Grid >

< Grid X: Name = "Ibinstalledexperience" Visibility = "Collapsed" >
< Rectangle Fill = "Azure"
Stroke = "Lightblue"
Radiusx = "10"
Radiusy = "10"
Margin = "20" />

< Textblock Text = "This program has been installed locally ."
Fontsize = "30"
Margin = "30"
Textwrapping = "Wrap"
Horizontalalignment = "Center"
Verticalalignment = "Center" />
</ Grid >

< Grid X: Name = "Oobexperience"
Visibility = "Collapsed" >

< Rectangle Fill = "Azure"
Stroke = "Lightblue"
Radiusx = "10"
Radiusy = "10"
Margin = "20" />

< Textblock Text = "This program is opened locally"
Fontsize = "30"
Margin = "30"
Textwrapping = "Wrap"
Horizontalalignment = "Center"
Verticalalignment = "Center" />
</ Grid >

</ Grid >

CS code:

   Public     Partial     Class Mainpage: usercontrol
{
Public Mainpage ()
{
Initializecomponent ();
// Interface initialization events
Loaded + = Mainpage_loaded;
// Button click event
Installbutton. Click + = Instclick;
// Application. installstatechanged event
// Occurs when the value of the installstate attribute is changed.
Application. Current. installstatechanged + = Oninstallstatechanged;
}

/// <Summary>
/// Update user interface
/// </Summary>
Private Void Updateuserinterface ()
{
// Application. isrunningoutofbrowser attribute
// Gets a value indicating whether the application is started out of the browser.
If (Application. Current. isrunningoutofbrowser)
{
// If you start a program outside the browser, the page is oobexperience Grid
Oobexperience. Visibility = Visibility. visible;
Ibnotinstalledexperience. Visibility = Visibility. collapsed;
Ibinstalledexperience. Visibility = Visibility. collapsed;
}
Else
{
// Installstate Enumeration
// Notinstalled has not installed the application to run outside the browser.
// Installing is installing this application to run outside the browser.
// Installed has installed the application to run outside the browser.
// Installfailed cannot install this application to run outside the browser.
If (Application. Current. installstate = Installstate. installed)
{
// If the program is started for the browser and installed locally, the page is ibinstalledexperience Grid
Ibinstalledexperience. Visibility = Visibility. visible;
// Hide other Grids
Ibnotinstalledexperience. Visibility = Visibility. collapsed;
Oobexperience. Visibility = Visibility. collapsed;
}
Else
{
// If the program is started for the browser and is not installed locally, the page is ibnotinstalledexperience Grid
Ibnotinstalledexperience. Visibility = Visibility. visible;
// Hide other Grids
Ibinstalledexperience. Visibility = Visibility. collapsed;
Oobexperience. Visibility = Visibility. collapsed;
}
}
}

Void Oninstallstatechanged ( Object Sender, eventargs E)
{
Updateuserinterface ();
}

Void Mainpage_loaded ( Object Sender, routedeventargs E)
{
Updateuserinterface ();
}

Void Instclick ( Object Sender, routedeventargs E)
{
// Application. Install Method
// Try to install the application so that the application can run outside the browser.
// This method can only work in the event handler of the event initiated by the user, and can work normally only when the Application List is correctly configured to enable external browser support.
// If these conditions are not met, this method returns false and the installation dialog box is not displayed.
// If the application requires a higher level of trust, this method returns true before the installation dialog box is displayed.
Application. Current. Install ();
}

}

Success !!!

author: memories of lost youth
Source: http://www.cnblogs.com/lukun/
copyright of this Article It is shared by the author and the blog site. You are welcome to repost it, but this statement must be kept without the author's consent, and in the Article page obvious position to give the original connection, if there is a problem, you can contact me through the http://www.cnblogs.com/lukun/ , thank you very much.

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.