Silverlight全屏模式切换

后台代码:

 

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interop;
namespace Full
{
    public partial class Page : UserControl
    {
        public Page()
        {
            // 需要初始化变量
            InitializeComponent();
            Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
        }

        private void btn_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)
            {
                btn.Background = new SolidColorBrush(Colors.Green);
                btn.Content = "Full Screen Mode";
            }
            else
            {
                btn.Background = new SolidColorBrush(Colors.Red);
                btn.Content = "Normal Mode";
            }

        }
    }
}

 

前台代码:

 

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="Full.Page"
 Width="640" Height="480">

 <Canvas Background="#46461F">
  <Button x:Name="btn" Background="Red" Width="200" Height="80" Canvas.Top="80" Canvas.Left="150" Content="Full Screen!" FontSize="20" Click="btn_Click"/>
 </Canvas>
</UserControl>

 

posted on 2009-07-16 17:35  晴天1848  阅读(332)  评论(0)    收藏  举报