Silverlight全屏模式切换 - 洛阳知道 免费ASP.NET/Java程序员培训

Silverlight全屏模式切换

发布时间: 2010-07-23 12:59:49  约 69 人浏览

记得引用命名空间using System.Windows.Interop;

后台代码:

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>

热门文章

友情链接: 围棋教学网 我的博客 大气象学习乐园 博客园 会计培训 洛阳知道论坛 梦想开始的地方 python课堂 铁闸网 GHS可用IP 我就要嗨吧 DJ摇摇网
给我留言
[关闭]