新手刚接触WPF,感觉还挺好用的~
最近想用WPF实现一个类似播放器能全屏又能按ESC退出全屏的功能,网上搜了很多,代码又长又不能正常运行,终于找到一个很简单的方法
//单击进入全屏
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Topmost = true;
this.WindowStyle = System.Windows.WindowStyle.None;
this.WindowState = System.Windows.WindowState.Maximized;
}
//按Esc键退出全屏
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)//Esc键
{
this.WindowState = System.Windows.WindowState.Normal;
this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
}
}