WPF 设置窗体 Window的 WindowStyle=“None“ 上方有白条问题

WPF 重写Window窗体的样式为None,上方有一条白条线,如下图:
在这里插入图片描述
解决方案:
Window窗体属性设置:ResizeMode=“CanMinimize”

        //
        // 摘要:
        //     获取或设置调整大小模式。
        //
        // 返回结果:
        //     一个 System.Windows.ResizeMode 值,该值指定调整大小模式。
        public ResizeMode ResizeMode { get; set; }
#region 程序集 PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\PresentationFramework.dll
#endregion


namespace System.Windows
{
    //
    // 摘要:
    //     指定是否可以调整窗口的大小,并且,如果是这样,如何可以调整它。 使用 System.Windows.Window.ResizeMode 属性。
    [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]
    public enum ResizeMode
    {
        //
        // 摘要:
        //     不能调整窗口的大小。 最小化 和 最大化 按钮不显示在标题栏中。
        NoResize = 0,
        //
        // 摘要:
        //     一个窗口仅可以最小化和还原。 最小化 和 最大化 按钮是显示,但仅限于 最小化 按钮才可用。
        CanMinimize = 1,
        //
        // 摘要:
        //     可以调整窗口的大小。 最小化 和 最大化 按钮都显示并启用。
        CanResize = 2,
        //
        // 摘要:
        //     可以调整窗口的大小。 最小化 和 最大化 按钮都显示并启用。 大小调整手柄将显示在窗口的右下角。
        CanResizeWithGrip = 3
    }
}

解决之后显示如下:
在这里插入图片描述
整体代码参考如下:

<Window x:Class="Solution.SpaceDemo.Window1"
        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:Solution.SpaceDemo"
        mc:Ignorable="d"
        Title="Window1" Height="72" Width="881" WindowStyle="None" Background="Transparent"  
        ResizeMode="CanMinimize">
    <Grid>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <StackPanel Orientation="Horizontal" Height="72" x:Name="barWidth0" Width="425">
                <Button Content="打开教材0"></Button>
                <Button Content="选择0"></Button>
                <Button Content="画笔0"></Button>
                <Button Content="板擦0"></Button>
                <Button Content="圈选0"></Button>
                <Button Content="聚焦0"></Button>
                <Button Content="学科工具0"></Button>
                <Button Content="交互0"></Button>
                <Button Content="录制0"></Button>
                <Button Content="本地文件0"></Button>
            </StackPanel>
            <ToggleButton Margin="0,0,0,0" Width="150"  Height="72" Content="ToggleButton" FontSize="30">
                <ToggleButton.Triggers>
                    <EventTrigger RoutedEvent="ToggleButton.Checked">
                        <BeginStoryboard>
                            <Storyboard >
                                <DoubleAnimation Duration="0:0:2" To="0" Storyboard.TargetName="barWidth0" Storyboard.TargetProperty="Width"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                        <BeginStoryboard>
                            <Storyboard >
                                <DoubleAnimation Duration="0:0:2" To="425" Storyboard.TargetName="barWidth0" Storyboard.TargetProperty="Width"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </ToggleButton.Triggers>
            </ToggleButton>
        </StackPanel>
    </Grid>
</Window>

备注:如果添加WindowStyle=“None” 和ResizeMode="CanMinimize"同时设置,就不会显示横向导航条

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值