【问题标题】:How to make title bar disappear in WPF window?如何使标题栏在 WPF 窗口中消失?
【发布时间】:2013-03-03 00:54:09
【问题描述】:

我知道以前有人问过这个问题,但我已经尝试过答案:

两者都不起作用,标题栏文本就在那里,我无法将我的网格移动到窗口的顶部,这样网格就占据了整个窗口。我被困在这上面了。

窗口的 XAML:

<Window x:Class="PlayWPF.TimerSlideWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="95" Width="641" WindowStyle="None" 
    ResizeMode="CanResize" AllowsTransparency="False">
   <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
       <Slider Height="42" HorizontalAlignment="Left" Margin="10,14,0,0" 
               Name="sldTime" VerticalAlignment="Top" Width="495" />
       <TextBox FontSize="18" Height="29" HorizontalAlignment="Left" 
                Margin="510,10,0,0" Name="txtTime" Text="00:00:00" 
                TextAlignment="Center" VerticalAlignment="Top" Width="93" />
   </Grid>
</Window>

【问题讨论】:

  • @HighCore 所说的......您链接的帖子中的代码工作正常。
  • WindowStyle="None" 这不正是您要找的吗???
  • @SandraWalters 这很有趣,也很讽刺(因为有成群的开发人员抱怨 XAML 太难读了)我到底怎么感觉阅读 XAML 比阅读英文更舒服......这发生在你身上吗?
  • @HighCore 阅读 Xaml 非常有意义;阅读 VB 让我想睁大眼睛 :)
  • 如果我理解正确,代码会做你想做的事。但如果你还希望它最大化,添加 WindowState="Maximized"...

标签: wpf xaml window titlebar


【解决方案1】:

尝试将标题高度设置为 0

<Window x:Class="BorderlessWindow.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    WindowStyle="None"
    WindowStartupLocation="CenterScreen"
    ResizeMode="CanResize">

 //remove the border, glassframe, but keep the ability to resize
<WindowChrome.WindowChrome>
    <WindowChrome GlassFrameThickness="0" CornerRadius="0" CaptionHeight="0"/>
</WindowChrome.WindowChrome>

<Grid>
    <TextBlock Text="Resizeable Window" HorizontalAlignment="Center" FontSize="30"/>  
</Grid>

【讨论】:

    【解决方案2】:

    尝试设置 TitleBarHeight="0"

    【讨论】:

    • 在使用现有答案添加旧问题的答案时,有助于解释您的答案有何不同以及为什么它可能会更好。
    • Window 上没有 TitleBarHeight 属性。
    【解决方案3】:

    我认为您应该使用 ShowTitleBar="False" 并返回到应用程序中的任何位置,无论是在 Xaml 文件中还是在后面的代码中。这应该可以解决问题

    【讨论】:

    • Window上没有这样的属性ShowTitleBar
    【解决方案4】:

    您需要将WindowStyle 属性设置为None,就像我在this answer 中概述的那样

    <Window ...
        WindowStyle="None"
        WindowState="Maximized"
        WindowStartupLocation="CenterScreen">
    

    如果您想隐藏整个窗框并自己构建,也可以设置AllowsTransparency="True"Background="Transparent"

    根据添加到问题的代码进行更新

    您刚刚发布的代码对我来说很好用。没有标题栏,虽然因为你指定了ResizeMode="CanResize"所以有一个Resize边框

    您的窗口顶部确实有一些空白,但那是因为您为 Slider 和 TextBox 指定了一个顶部边距(当您指定一个包含 4 个数字的边距时,它会依次为左、上、右、下,因此第二个数字是您的最高边距)

    【讨论】:

    • 它确实在宽度之后说 WindowStyle = "None"。我已将边距更改为 0,但它仍然显示左上角的窗口,我无法向上移动网格以占用该空间。谢谢
    • @StewartStoakes 你能贴一张你的窗口的截图吗?如果您设置网格的Background 颜色也会有所帮助,这样您就可以准确地看到边界的位置。我将您问题中的代码复制并粘贴到一个新项目中,并且标题保持隐藏得很好(另外,您的 Title 属性是空白的,所以我不确定它从哪里获取“窗口”......你确定你'只显示这一个窗口,而第二个没有显示?)
    • 完美! AllowsTransparency="True"Background="Transparent" 正是我制作自定义闪屏所需要的。 :)
    【解决方案5】:
    <Window x:Class="BorderlessWindow.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525"
            WindowStyle="None"
            BorderBrush="Black"
            BorderThickness="5"
            AllowsTransparency="True"
            >
        <Grid>
            <TextBlock Text="Title Less Window" HorizontalAlignment="Center" FontSize="15" Margin="10" />
        </Grid>
    </Window>
    

    上面的代码可以很好地解决您的问题“如何使标题栏在 WPF 窗口中消失?”

    【讨论】:

    • 设置 AllowsTransparency="True" 并设置边框笔刷和边框厚度。这将显示边框。 WindowStyle="None" ResizeMode="CanResize" AllowsTransparency="True" BorderThickness="1" BorderBrush="Black"
    • 如果您希望能够调整大小,请设置 ResizeMode=CanResizeWithGrip
    猜你喜欢
    • 2011-07-03
    • 2020-01-09
    • 2012-04-16
    • 2011-01-25
    • 2013-08-05
    • 2014-08-24
    • 2012-03-10
    • 2017-10-25
    • 2014-08-16
    相关资源
    最近更新 更多