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 = "全屏"; } } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。