OOB application, OOB update, and webbrowser

Source: Internet
Author: User

First, learn the OOB application.

SL provides the out-of-browser function. We will use an instance to learn about this function and use the webbrowser function in this example.

First create a project, slwebbrower

Create an install. XAML. in XAML, there is an install button and a textblock that displays the installation content,

The event of this button is actually very easy to determine whether to install. If not, install it.

The Code is as follows:

private void button1_Click(object sender, RoutedEventArgs e)        {            if (App.Current.InstallState != InstallState.Installed)            {                App.Current.Install();            }        }

We will add an installation status event to the page. In this event, we will judge the installation status of the current application and display the corresponding prompt in textbolck. The Code is as follows:

 

Code

 
Public install ()
{
This. Loaded + = new routedeventhandler (install_loaded );
Initializecomponent ();
App. Current. installstatechanged + = new eventhandler (current_installstatechanged );
}

Private void updateinstallstate ()
{
Switch (App. Current. installstate)
{
Case installstate. notinstalled:
Button1.visibility = system. Windows. Visibility. visible;
Textblock1.text = "click the Install button to install ";
Break;
Case installstate. Installing:
Button1.visibility = system. Windows. Visibility. collapsed;
Textblock1.text = "installing... ";
Break;
Case installstate. installfailed:
Button1.visibility = system. Windows. Visibility. visible;
Textblock1.text = "Installation failed. Please try again ";
Textblock1.foreground = new solidcolorbrush (colors. Red );
Break;
Case installstate. installed:
Button1.visibility = system. Windows. Visibility. visible;
Textblock1.text = "Installation complete! ";
Textblock1.foreground = new solidcolorbrush (colors. Green );
Break;

}
}

 

 

 

After the installation interface is completed, let's take a look at the processing in mainpage.

Put a textblock and a webbrowser control in mainpage. We set the source of webbrowser to http: // localhost/default.html;

This will load default.html to the mainpage at runtime, so that the user does not know that the position of the form is a webpage. Here, a small box is displayed in the lower right corner of the screen to tell the user

Default.html is loaded to let users know what the software is doing.

In this way, in the loadcompleted event of webbrowser, we use icationicationwindow form to implement this function. The Code is as follows:

 

Code

 Private void webbrowser1_loadcompleted (Object sender, system. Windows. Navigation. navigationeventargs E)
{
Icationicationwindow nw = new notificationwindow ();
NW. content = new textblock {text = "HTML loaded! "};
NW. Show (5000 );
}

 

Next, we will add a judgment in the application_startup event of APP. CS to determine whether OOB is running or not. If not, we will prompt you to install

The Code is as follows:

 private void Application_Startup(object sender, StartupEventArgs e)        {            if (App.Current.IsRunningOutOfBrowser && App.Current.HasElevatedPermissions)            {                this.RootVisual = new MainPage();            }            else            {                this.RootVisual = new Install();            }        }
Finally, you need to set the project properties so that the project has full permission to run under OOB. The specific settings (note checkbox) will allow the project to run in OOB mode, below we will discuss the running effect. The update Implementation in OOB mode only needs to judge whether the program is up to date at startup. If not, the Code is as follows:
Public app () {If (App. current. installstate = system. windows. installstate. installed) {app. current. checkanddownloadupdatecompleted + = new checkanddownloadupdatecompletedeventhandler (current_checkanddownloadupdatecompleted); app. current. checkanddownloadupdateasync ();} This. startup + = This. application_startup; this. exit + = This. application_exit; this. unhandledexception + = This. application_unhandled Exception; initializecomponent ();} void current_checkanddownloadupdatecompleted (Object sender, checkanddownloadupdatecompletedeventargs e) {If (E. updateavailable & E. error = NULL) {MessageBox. show ("the application has been installed and will take effect next time");} else if (E. error! = NULL) {MessageBox. Show ("Installation failed" + E. Error. Message );}}

If you execute this operation on the local machine, you can update it. If digital signatures are required for publishing, this study has not been completed for a long time. The website we learned has been posted for further research. Please give us some advice on how to study it.

Http://msdn.microsoft.com/library/dd550721 (vs.95). aspx; http://www.cnblogs.com/chuifeng/archive/2010/08/20/1804294.html

 

During the study of OOB, we studied how to install offline programs to the client.

One installation instance:

"C: \ Program Files \ microsoft Silverlight \ sllauncher.exe"

/Install: "slwebbrower. xap"

/Origin: "http: // 192.168.1.101: 8088/clientbin/slwebbrower. xap"

/Shortcut cut: desktop + startmenu

/Overwrites

The following describes the xap parameters for local installation of Silverlight.

Install

  • /Install: "xapfile"-Xapfile is the file name/file path. xap file., e. g./install: "C: \ temp \ sample. xap"
  • /Origin: "Xapuri" -Here, Xapuri is the. xap file in it and will be the URI from the past. If it is not installed on the command line
    • E.g. /origin: "http://example.com/sample.xap ". this URI will be used as the origin site for security purposes. for example, for sandbox applications, the Silverlight network requires a policy file to check the network request time domain ratio to other source sites. The origin can also be the unique ID of an application. the Xapuri must be an absolute URI instead of a relative Uri, and must start with HTTP:, via https: or file :.
  • /Overwrite-- (Optional) overwrites any xap installed before the Xapuri.

Delete

  • /Uninstall-Uninstall the specified application/origin. This is the same/origin function used to install the application initially.
  • /Origin: "Xapuri"-Installation with the same/Origin

 

If something is wrong, please make common progress.

 

OOB learning example code: http://files.cnblogs.com/Clivia/SLWebBrower.rar

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.