MainPage.xaml.cs
上传用户:zhouwei825
上传日期:2021-04-15
资源大小:51k
文件大小:2k
源码类别:

SilverLight

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using System.Windows.Interop;//引入命名空间Interop
  13. namespace FullScreen
  14. {
  15.     public partial class MainPage : UserControl
  16.     {
  17.         public MainPage()
  18.         {
  19.             InitializeComponent();
  20.             //为全屏添加事件
  21.             Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
  22.         }
  23.         //全屏事件中如果是全屏按钮则显示Full Screen,否则显示Small Screen
  24.         void Content_FullScreenChanged(object sender, EventArgs e)
  25.         {
  26.             Content contentObject = Application.Current.Host.Content;
  27.             if (contentObject.IsFullScreen)
  28.             {
  29.                 tbClick.Background = new SolidColorBrush(Colors.Gray);
  30.                 tbClick.Content = "Full Screen";
  31.             }
  32.             else
  33.             {
  34.                 tbClick.Background = new SolidColorBrush(Colors.Green);
  35.                 tbClick.Content = "Small Screen";
  36.             }
  37.         }
  38.         //点击全屏
  39.         private void Button_Click(object sender, RoutedEventArgs e)
  40.         {
  41.             //获取当前Silverlight插件"Content"对象,并设置IsFullScreen属性,点击后全屏,再次点击恢复
  42.             Content contentObject = Application.Current.Host.Content;
  43.             contentObject.IsFullScreen = !contentObject.IsFullScreen;
  44.         }
  45.     }
  46. }