首页 > 其他分享 >WPF背景页面布局

WPF背景页面布局

时间:2022-08-30 21:47:25浏览次数:56  
标签:object RoutedEventArgs void 布局 private WindowState TestWindow WPF 页面

<Window x:Class="TimeCalc.View.TestWindow"
        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:TimeCalc.View"
        mc:Ignorable="d" WindowStartupLocation="CenterScreen" Background="Transparent" FontFamily="Microsoft YaHei" FontSize="12" FontWeight="ExtraLight"
        Title="MES" Height="700" Width="1150">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="-1"/>
    </WindowChrome.WindowChrome>
    <Grid>
        <Grid.Background>
            <RadialGradientBrush>
                <GradientStop Color="#FF285173" Offset="0"/>
                <GradientStop Color="#FF244967" Offset="0.3"/>
                <GradientStop Color="#FF14273A" Offset="1"/>
            </RadialGradientBrush>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="45"/>
            <RowDefinition />
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <Border BorderBrush="#5518AABD" BorderThickness="0,0,0,1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="60"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Image Source="../Asserts/Images/logo.png" Margin="0,7"/>
                <StackPanel Grid.Column="1" VerticalAlignment="Center">
                    <TextBlock Text="{Binding Title,RelativeSource={RelativeSource AncestorType=Window}}" Foreground="White" FontSize="16"/>
                    <TextBlock Text="xxxxxxxxxxxx" Foreground="LightGray" FontSize="9" Margin="0,2,0,0"/>
                </StackPanel>
                <Grid Grid.Column="2">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="13"/>
                    </Grid.RowDefinitions>
                    <Border HorizontalAlignment="Right" WindowChrome.IsHitTestVisibleInChrome="True" Background="Transparent" Width="200">
                        <!--遮挡住自带的三个按钮-->
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button Content="&#xea6a;"  Style="{StaticResource ControlButtonStyle}" Click="MinClick"/>
                            <Button Content="&#xea6b;" Style="{StaticResource ControlButtonStyle}" Click="MaxNormalClick"/>
                            <Button Content="&#xe668;" Style="{StaticResource ControlButtonStyle}" Background="DarkRed" Click="CloseClick"/>
                        </StackPanel>
                    </Border>
                    <Border Grid.Row="1" BorderBrush="#5518AABD" BorderThickness="0,1,0,0"/>
                    <Border Grid.Row="1" Margin="0,3,0,2">
                        <Border.Background>
                            <VisualBrush TileMode="Tile" Viewport="0,0,7,7" ViewportUnits="Absolute">
                                <VisualBrush.Visual>
                                    <Grid Width="20" Height="20">
                                        <Line X1="0" Y1="10" X2="10" Y2="0" Stroke="Gray" StrokeThickness="1"/>
                                    </Grid>
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </Border.Background>
                    </Border>
                </Grid>
            </Grid>
        </Border>

        <Border Grid.Row="2" BorderBrush="#5518AABD" BorderThickness="0,1,0,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <Border  Margin="0,5">
                    <Border.Background>
                        <VisualBrush TileMode="Tile" Viewport="0,0,7,7" ViewportUnits="Absolute">
                            <VisualBrush.Visual>
                                <Grid Width="20" Height="20">
                                    <Line X1="0" Y1="10" X2="10" Y2="0" Stroke="Gray" StrokeThickness="1"/>
                                </Grid>
                            </VisualBrush.Visual>
                        </VisualBrush>
                    </Border.Background>
                </Border>
                <TextBlock Grid.Column="1" Text="2022 ©、®、™ Co. Ltd." Foreground="DarkRed" VerticalAlignment="Center" FontSize="11" FontWeight="Bold" Margin="10,1"/>
            </Grid>
        </Border>
    </Grid>
</Window>
TestWindow.xaml
public partial class TestWindow : Window
    {
        public TestWindow()
        {
            InitializeComponent();
        }
        private void CloseClick(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void MinClick(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void MaxNormalClick(object sender, RoutedEventArgs e)
        {
            //判断是否以及最大化,最大化就还原窗口,否则最大化
            if (this.WindowState == WindowState.Maximized)
                this.WindowState = WindowState.Normal;
            else
                this.WindowState = WindowState.Maximized;
        }
    }
TestWindow.xaml.cs
<Style TargetType="Button" x:Key="ControlButtonStyle">
            <Setter Property="Width" Value="40"/>
            <Setter Property="Background" Value="#11FFFFFF"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontFamily" Value="Asserts/Fonts/#iconfont"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="{TemplateBinding Background}">
                            <Border Name="root">
                                <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="root" Property="Background" Value="#33FFFFFF"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
ControlButtonStyle

 

标签:object,RoutedEventArgs,void,布局,private,WindowState,TestWindow,WPF,页面
From: https://www.cnblogs.com/Nicolasap/p/16640926.html

相关文章