设置WPF无边框(隐藏最小化、最大化和关闭按钮),自定义功能模块
第一步:在.xaml文件中编写界面代码
WindowStyle="None"
ShowIconOnTitleBar="False"
ShowTitleBar="False"
ShowMaxRestoreButton="False"
ShowCloseButton="False"
ShowMinButton="False"
设置之后,可能会出现无法拖动以及变换窗体的问题,需要在ViewModel中编写自定义功能模块。
第二步:编写自定义功能触发模块代码
1、在.xaml文件的控件中设置Command
<Button Command="{Path=DataContext.TestCommand}"/>
2、在ViewModel中的.cs文件中编写自定义功能模块代码
public FunctionCommand TestCommand => new BaseCommand(a =>
{
switch (a)
{
// 关闭当前窗口
case "Exit":
Environment.Exit(0);
break;
// 还原 或者 最大化当前窗口
case "Normal":
if(Application.Current.MainWindow.WindowState == WindowState.Normal)
{
Application.Current.MainWindow.WindowState = WindowState.Maximized;
break;
}
if (Application.Current.MainWindow.WindowState == WindowState.Maximized)
{
Application.Current.MainWindow.WindowState = WindowState.Normal;
break;
}
break;
// 最小化当前窗口
case "Minimized":
Application.Current.MainWindow.WindowState = WindowState.Minimized;
break;
}
});