Silverlight 2 series (7): Full Screen mode supported

Source: Internet
Author: User
Overview

The release of Silverlight 2 Beta 1 brings us a lot of surprises from Runtime and Tools, such as supporting the framework languages Visual Basic, Visual C #, IronRuby, Ironpython, A series of new features such as JSON, Web Service, WCF, and Sockets support. The one-step learning Silverlight 2 series article takes you to Silverlight 2 development quickly.

This article is the seventh article in the series and describes how to use full screen mode in Silverlight 2.

Full Screen mode

The full-screen mode is sometimes very useful and provides good support in Silverlight. The implementation is also very simple. In fact, there is only one line of code to write a simple XAML.

<Canvas Background="#46461F">    <Button x:Name="toggleButton" Background="Red" Width="200" Height="80"            Canvas.Top="80" Canvas.Left="150" Content="Toggle Full Screen"            FontSize="20" Click="toggleButton_Click"/>    <Image x:Name="image" Source="smile_6.png"            Canvas.Top="100" Canvas.Left="40"></Image></Canvas>

Introduce namespace

using System.Windows.Interop;

Click the button to add the implementation code to the event.

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

Obtain the current Silverlight plug-in "Content" object and set the IsFullScreen attribute. After running, click the button to change to full screen mode. click the button again (or Press Esc) to return to normal mode.

Capture related events

Sometimes, we need to add another code when switching between full screen mode and normal mode. In this case, we can use the event FullScreenChanged.

public Page(){    InitializeComponent();    Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);}

Event Processing

private void Content_FullScreenChanged(object sender, EventArgs e){    Content contentObject = Application.Current.Host.Content;    if (contentObject.IsFullScreen)    {        toggleButton.Background = new SolidColorBrush(Colors.Green);        toggleButton.Content = "Full Screen Mode";    }    else    {        toggleButton.Background = new SolidColorBrush(Colors.Red);        toggleButton.Content = "Normal Mode";    }}

When switching between normal mode and full screen mode, the background color and text of the button are changed. Click the button after running:

Switch to normal mode:

The complete code is as follows:

public partial class Page : UserControl{    public Page()    {        InitializeComponent();        Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);    }    private void toggleButton_Click(object sender, RoutedEventArgs e)    {        Content contentObject = Application.Current.Host.Content;        contentObject.IsFullScreen = !contentObject.IsFullScreen;    }    private void Content_FullScreenChanged(object sender, EventArgs e)    {        Content contentObject = Application.Current.Host.Content;        if (contentObject.IsFullScreen)        {            toggleButton.Background = new SolidColorBrush(Colors.Green);            toggleButton.Content = "Full Screen Mode";        }        else        {            toggleButton.Background = new SolidColorBrush(Colors.Red);            toggleButton.Content = "Normal Mode";        }    }}
Conclusion

This article briefly introduces the full-screen mode support in Silverlight 2. You can download the sample code in this article from here.

Next article: Learn Silverlight 2 series (8) step by step: encapsulate the view of controls using styles

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.