Slow and steady Silverlight (44)

Source: Internet
Author: User
Tags xmlns silverlight

The enhancements of the OOB of the slow-running Silverlight (44)-4.0 browser run (out of Browser) and its new NotificationWindow

Introduced

New features of the Silverlight 4.0 OOB model:

* New Closing Event

* Implementation of the program in the OOB mode of Automatic Updates

* NotificationWindow-Displays the notification window in OOB mode, which is toast

* Implementation of Custom NotificationWindow

Online Demo

Http://www.cnblogs.com/webabcd/archive/2010/08/09/1795417.html

Example

1, OOB (out of Browser) model review, and its new Closing events

Demo.xaml

Code

<navigation:page x:class= "Silverlight40.OutOfBrowser.Demo"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
Xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation= "Clr-namespace:system.windows.controls;assembly=system.windows.controls.navigation"
Title= "Other Page" >
<grid x:name= "LayoutRoot" >
<stackpanel horizontalalignment= "Left" >
<button name= "Btnoutofbrowser" margin= "click=" Btnoutofbrowser_click
<button name= "btnclose" margin= "content=" "Close" click= "btnClose_Click"/>
<textblock text= "OOB mode of Detection of network conditions, as well as the upgrade of the program described in this directory Autoupdatedemo.xaml" margin= "5"/>
<textblock text= "OOB mode toast (and compared to Popup) see Notificationwindowdemo.xaml" margin= "5" in this directory/>
<textblock text= the content and style of custom NotificationWindow in OOB mode see the Customnotificationwindowdemo.xaml "margin=" 5 "in this directory/>
</StackPanel>

</Grid>
</navigation:Page>

Demo.xaml.cs

Code

/*
* The Silverlight 3.0 era has the following characteristics
* Application.installstatechanged-Events that are triggered when the dependent state of the running outside the browser has changed
* Application.installstate-related state of running outside the browser [System.Windows.InstallState enum]
* notinstalled-run in browser
* Installing-Install to Desktop
* Installed-run outside the browser
* installfailed-Error occurred during installation to desktop
* Application.isrunningoutofbrowser-whether the current program is started from outside the browser
* Application.install ()-Install the Silverlight program outside the browser (uninstall can only be uninstalled by right-clicking the menu)
* Application.checkanddownloadupdateasync, application.checkanddownloadupdatecompleted-a pair of asynchronous methods/events, for updating a browser running Silverlight Program (Download a new version from the server)
*
* Enable OOB: Right-click-> properties on Silverlight Project-> Silverlight-> Select Enable running application out of the browser
* Configure OOB: Right-click-> properties on Silverlight projects-> Silverlight-> Out-of-browser settings can be set on the related parameters of "run out of browser" (or you can manually modify Prope Rties/outofbrowsersettings.xml)
*/

/*
* Debug the Silverlight program in OOB mode: Enable OOB mode, set the Silverlight project as the startup project, and then run
*/

/*
* This example is used to demonstrate the Closing event
* The application window in Application.current.mainwindow-oob mode. Property value is System.Windows.Window type
* Window.activate ()-Activates the window so that it has focus and is placed at the front
* Window.isactive-is the active window (get only)
* Window.close ()-Close window
* Window.closing-Events that are triggered before the window closes. Event parameter is System.ComponentModel.ClosingEventArgs type
* Closingeventargs.iscancelable-whether to cancel the window Shutdown event
* Closingeventargs.cancel-whether to cancel the window Shutdown event
*/
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Net;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Animation;
Using System.Windows.Shapes;
Using System.Windows.Navigation;
Namespace Silverlight40.outofbrowser
{
public partial class Demo:page
{
Public Demo ()
{
InitializeComponent ();
}
protected override void Onnavigatedto (NavigationEventArgs e)
{
if (App.Current.IsRunningOutOfBrowser)
btnoutofbrowser.content = "Uninstall";
Else
btnoutofbrowser.content = "Install";
Init ();
}
private void Btnoutofbrowser_click (object sender, RoutedEventArgs e)
{
if (! App.Current.IsRunningOutOfBrowser && App.Current.InstallState = = installstate.notinstalled)
App.Current.Install ();
Else
MessageBox.Show ("Already installed, using right key uninstall");
}
void Init ()
{
if (Application.Current.IsRunningOutOfBrowser)
Application.Current.MainWindow.Closing + = new Eventhandler<system.componentmodel.closingeventargs> ( mainwindow_closing);
}
void Mainwindow_closing (object sender, System.ComponentModel.ClosingEventArgs e)
{
if (MessageBox.Show) (confirm close?) "," confirmed ", messageboxbutton.okcancel) = = Messageboxresult.ok)
{
}
Else
{
if (e.iscancelable)
E.cancel = true;
}
}
private void btnClose_Click (object sender, RoutedEventArgs e)
{
if (Application.Current.IsRunningOutOfBrowser)
Application.Current.MainWindow.Close ();
}
}
}

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.