首页 > 代码库 > Silverlight FullScreen 全屏
Silverlight FullScreen 全屏
<UserControl x:Class="FullScreen.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Border HorizontalAlignment="Left" VerticalAlignment="Top" Padding="10" BorderThickness="1" CornerRadius="4" Background="#7F000000"> <StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Text="总CPU占用:" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="White"></TextBlock> <TextBlock x:Name="txtCPULoad" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="White"></TextBlock> </StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Text="当前CPU占用:" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="White"></TextBlock> <TextBlock x:Name="txtSLCPULoad" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="White"></TextBlock> </StackPanel> </StackPanel> </Border> <Button Content="正常" Height="47" HorizontalAlignment="Left" Margin="152,123,0,0" Name="btnFull" VerticalAlignment="Top" Width="68" Click="btnFull_Click" /> </Grid></UserControl>
cs代码
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Windows.Threading;namespace FullScreen{ public partial class MainPage : UserControl { Analytics myAnalytics; public MainPage() { InitializeComponent(); Loaded += new RoutedEventHandler(MainPage_Loaded); Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged); } void MainPage_Loaded(object sender, RoutedEventArgs e) { myAnalytics = new Analytics(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += new EventHandler(timer_Tick); timer.Start(); } void timer_Tick(object sender, EventArgs e) { txtCPULoad.Text = myAnalytics.AverageProcessorLoad.ToString(); txtSLCPULoad.Text = myAnalytics.AverageProcessLoad.ToString(); } void Content_FullScreenChanged(object sender, EventArgs e) { var content = Application.Current.Host.Content; if (content.IsFullScreen) { btnFull.Background = new SolidColorBrush(Colors.Yellow); LayoutRoot.Background = new SolidColorBrush(Colors.Yellow); } else { btnFull.Background = new SolidColorBrush(Colors.Red); LayoutRoot.Background = new SolidColorBrush(Colors.Red); } } private void btnFull_Click(object sender, RoutedEventArgs e) { var content = Application.Current.Host.Content; if (!content.IsFullScreen) { content.IsFullScreen = !content.IsFullScreen; btnFull.Content = "还原"; } else { content.IsFullScreen = !content.IsFullScreen; btnFull.Content = "全屏"; } } }}
Silverlight FullScreen 全屏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。