<Window x:Class="dnh_ocr.MainWindow"
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"
xmlns:local="clr-namespace:dnh_ocr"
mc:Ignorable="d"
Title="大挪耗www.ha0wen.top" Height="398" Width="506">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="30" GlassFrameThickness="-1" UseAeroCaptionButtons="False"/>
</WindowChrome.WindowChrome>
<Window.Resources>
<Style TargetType="{x:Type Panel}" x:Key="WinRootPanelStyle">
<Setter Property="Margin" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
<Setter Property="Margin" Value="7" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid ShowGridLines="True" IsHitTestVisible="True" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource WinRootPanelStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Height="30" Width="40" Content="—" BorderThickness="0" Click="最小化窗口"/>
<Button Height="30" Width="40" Content="口" BorderThickness="0" Click="全屏窗口"/>
<Button Height="30" Width="40" Content="X" BorderThickness="0" Click="关闭窗口">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock x:Name="TextBlock" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="#cc0000"/>
<Setter TargetName="TextBlock" Property="Foreground" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</Grid>
</Window>
加粗的代码是关键部分,NET8.0,另一段代码实现
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace dnh_ocr
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void 关闭窗口(object sender, RoutedEventArgs e)
{
Close();
}
private void 全屏窗口(object sender, RoutedEventArgs e)
{
WindowMax();
}
private void WindowMax()
{
if (this.WindowState == WindowState.Normal)
{
this.WindowState = WindowState.Maximized;
}
else
{
this.WindowState = WindowState.Normal;
}
}
private void 最小化窗口(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
}
}
发表回复