wpf 无边框窗体
程序员文章站
2022-03-08 08:06:01
...
<Window x:Class="UserControlDemo.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:UserControlDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" WindowStyle="None"
WindowChrome.WindowChrome="{DynamicResource WindowChromeKey}" Background="#1BA1E2" >
<Window.Resources>
<WindowChrome x:Key="WindowChromeKey">
<WindowChrome.ResizeBorderThickness>
<Thickness>5</Thickness>
</WindowChrome.ResizeBorderThickness>
</WindowChrome>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Content="Main Window" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="30"></Label>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Button x:Name="btnMinimize" Height="20" Width="20" Content="-" Click="BtnMinimize_Click"/>
<Button x:Name="btnMaximize" Height="20" Width="20" Content="□" Click="BtnMaximize_Click"/>
<Button x:Name="btnClose" Height="20" Width="20" Content="×" Click="BtnClose_Click"/>
</StackPanel>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 UserControlDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void BtnMaximize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Maximized;
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}