前台页面:
<Grid> <Button Content="全屏" Height="47" HorizontalAlignment="Left" Margin="157,124,0,0" Name="button1" VerticalAlignment="Top" Width="146" Click="button1_Click" /> </Grid>
后台代码:
bool Flag = false; private void button1_Click(object sender, RoutedEventArgs e) { // 设置全屏 if (Flag) { this.WindowState = System.Windows.WindowState.Normal; this.WindowStyle = System.Windows.WindowStyle.None; this.ResizeMode = System.Windows.ResizeMode.NoResize; this.Topmost = true; this.Left = 0.0; this.Top = 0.0; this.Width = System.Windows.SystemParameters.PrimaryScreenWidth; this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; Flag = false; } else { this.WindowState = System.Windows.WindowState.Normal; this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow; this.ResizeMode = System.Windows.ResizeMode.CanResize; this.Topmost = true; this.Left = 0.0; this.Top = 0.0; this.Width = 1350; this.Height = 768; Flag = true; }