WPF重写Window标题栏

复制代码
<Window x:Class="License.UI.DetailsInterface"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:License.UI"
             mc:Ignorable="d"   
              xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework" 
               Height="310"  Width="500"  ResizeMode="NoResize"  WindowStartupLocation="CenterOwner">
    <Window.Resources>
        <ResourceDictionary> 
            <Style x:Key="btn_nap" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border Background="{TemplateBinding Background}">
                                <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"></ContentPresenter>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Foreground" Value="Black"></Setter>
                <Setter Property="Background" Value="Transparent"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="Background" Value="Red"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <shell:WindowChrome.WindowChrome>
        <shell:WindowChrome CaptionHeight="35" x:Name="windowChrome" CornerRadius="0" GlassFrameThickness="0"/>
    </shell:WindowChrome.WindowChrome>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0"  x:Name="TitleBlock_Grid" Panel.ZIndex="1">
        <!- 标题栏内容-!>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button WindowChrome.IsHitTestVisibleInChrome="True"   x:Name="btn_Close" Content="✕" Style="{StaticResource btn_nap}" HorizontalAlignment="Right"    Click="btn_Close_Click" Height="30" Width="30"/>
            </StackPanel>
            <TextBlock x:Name="textBlock" Text="{DynamicResource MenuHelpActivate}" HorizontalAlignment="Left" Margin="10,8,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="87"/>
        </Grid>
        <Grid  Grid.Row="1">
            <!- Body内容 -!>
     

        </Grid>
    </Grid>
</Window>
复制代码

 

posted @   安静点--  阅读(173)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
历史上的今天:
2022-03-28 c++初始化列表
2022-03-28 深拷贝与浅拷贝
点击右上角即可分享
微信分享提示