IntroductionThis 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.
void Content_FullScreenChanged(object sender, EventArgs e){ MessageBox.Show("FullScreen Changed");}See the following screenshot.Resized EventResized 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 EventWhen 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 SilverlightWe can close the browser window with the help of HtmlWindow.Eval method. Which evaluates a string that contains arbitrary JavaScript code.Namespace: System.Windows.BrowserAssembly: 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.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.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: