基本思路是把原來的WindowStyle設定為None,然后自己弄一個標題欄
一、xmal
<Window x:Class="YKCore.WindowSetup" Name="WinMain"
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:YKCore"
mc:Ignorable="d"
WindowState="Maximized"
WindowStyle="None" SizeChanged="WinMain_SizeChanged"
Height="450" Width="800" BorderThickness="0" Background="{DynamicResource BackgroundColor}"
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2">
<!-- 最大化按鈕形狀 -->
<PathGeometry x:Key="pathMaximize">
<PathGeometry.Figures>
M1,1 L1 ,11 L11,11 L11,1 z M0,0 L12,0 L12,12 L0,12 z
</PathGeometry.Figures>
</PathGeometry>
<!-- 還原按鈕形狀 -->
<PathGeometry x:Key="pathRestore">
<PathGeometry.Figures>
M1,3 L1,11 L9,11 L9,3 z M3,1 L3,2 L10,2 L10,9 L11,9 L11,1 z M2 ,0 L12,0 L12,10 L10,10 L10,12 L0,12 L0,2 L2 ,2 z
</PathGeometry.Figures>
</PathGeometry>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Border BorderBrush="{DynamicResource ForeColor}" BorderThickness="2,2,2,0" Padding="10,0">
<Grid>
<!--自己畫個圖示,也就是一個圓角矩形里面寫了個字母M-->
<Rectangle Width="30" Height="28" Stroke="Yellow" StrokeThickness="1" HorizontalAlignment="Left" RadiusX="5" RadiusY="5" />
<TextBlock Text="M" Foreground="Yellow" Margin="10,0,0,0">
<TextBlock.RenderTransform>
<SkewTransform AngleX="-15"/>
</TextBlock.RenderTransform>
</TextBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
<Button x:Name="BtnMin" Width="28" Height="28" Click="BtnMin_Click" >
<Path Data=https://www.cnblogs.com/catzhou/p/"M0,5 L12,5 L12,6 L0,6 z" Fill="{DynamicResource ForeColor}" Width="12" Height="12"/>
二、后臺代碼(幾個事件)
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void BtnMax_Click(object sender, RoutedEventArgs e)
{
this.WindowState = this.WindowState != WindowState.Maximized ? WindowState.Maximized : WindowState.Normal;
}
private void BtnMin_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void WinMain_SizeChanged(object sender, SizeChangedEventArgs e)
{
PMax.Data = https://www.cnblogs.com/catzhou/p/this.WindowState == WindowState.Maximized ? Resources["pathRestore"] as Geometry : Resources["pathMaximize"] as Geometry;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/146.html
標籤:WPF
上一篇:布局控制元件
