SIGN UP MEMBER LOGIN:    
ARTICLE

Application Events of Silverlight

Posted by Priya Linge Articles | Silverlight with C# August 03, 2011
This article demonstrates the SilverlightHost.Content events of Silverlight and how can we close the application window in Silverlight.
Reader Level:


Introduction

This article demonstrates the SilverlightHost.Content events of Silverlight and how can we close the application window in Silverlight.

Step 1: We mainly have three Hosts. Content events in a Silverlight application as follows.

  1. Application.Current.Host.Content.FullScreenChanged Event.
  2. Application.Current.Host.Content.Resized Event.
  3. Application.Current.Host.Content.Zoomed.

FullScreenChanged Event

FullScreenChanged event occurs when we change the FullScreen property of the Silverlight plug-in.

Either enters or exits full-screen mode.

public event EventHandler FullScreenChanged.

Change the fullScreen property of Silverlight.

Take one Button named as FullScreen.

On Button Click events make screen in fullscreen mode as follows.

private void btnfullscreen_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Host.Content.IsFullScreen =    !Application.Current.Host.Content.IsFullScreen;
}

Here we changed the fullscreen property of Silverlight plug-in.

See the following screenshot.

Application events of silverlight

When we click on Full Screen Button, screen become in a Full screen mode.

And at that time the FullScreenChaned event fires, because whenever the FullScreen property of the Silverlight plug-in changes, this event fires.

Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

void Content_FullScreenChanged(object sender, EventArgs e)
{
    MessageBox.Show("FullScreen Changed");
}

See the following screenshot.

Application events of silverlight

Resized Event

Resized event occurs when the ActualHeight or the ActualWidth of the Silverlight plug-in changes.

When we maximize the window this event is fired and we can get the height and width of the window at maximize state with the help of this event.

Application.Current.Host.Content.Resized += new EventHandler(Content_Resized);

void Content_Resized(object sender, EventArgs e)

{
    MessageBox.Show("Resized");
 //Get height and width of window when it get resized.
    double height = Application.Current.Host.Content.ActualHeight;
    double width = Application.Current.Host.Content.ActualWidth;
 
}


Zoomed Event

When we change the Zoom setting in the host browser window, this event is fired.

Application.Current.Host.Content.Zoomed += new EventHandler(Content_Zoomed);

void Content_Zoomed(object sender, EventArgs e)
{
   MessageBox.Show("Zoomed");
          
}


Step 2: Close the application window in Silverlight

We can close the browser window with the help of HtmlWindow.Eval method. Which evaluates a string that contains arbitrary JavaScript code.

Namespace: System.Windows.Browser

Assembly: System.Windows.Browser (in System.Windows.Browser.dll)

We have CloseWindow button. On the click event of the button write the following code.

private void btnCloseWindow_Click(object sender, RoutedEventArgs e)
{
    HtmlPage.Window.Eval("window.close();");
}

Output will looks like as following.

Application events of silverlight

Summary:

We have some SilverlightHose.Content events in Silverlight with the help of that we can get the idea about the screen mode in Silverlight and also how can we full screen the application, close the browser window and resize the window.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor