如何使 WPF 窗口中的标题栏消失?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15413263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:44:06  来源:igfitidea点击:

How to make title bar disappear in WPF window?

wpfxamlwindowtitlebar

提问by Stewart Stoakes

I know this has been asked before but I've tried answers:

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

and neither work, the title bar text sits there and im unable to move my grid up to the top of the window so that the grid takes up the whole window. I' am stuck on this.

两者都不起作用,标题栏文本位于那里,我无法将我的网格向上移动到窗口顶部,以便网格占据整个窗口。我被困在这个问题上。

The XAML for the window :

窗口的 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>

回答by Rachel

You need to set the WindowStyleproperty to None, like I outlined in this answer

您需要将该WindowStyle属性设置为None,就像我在此答案中概述的那样

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

You can also set AllowsTransparency="True"and Background="Transparent"if you wish to hide the entire window frame and build your own.

您还可以设置AllowsTransparency="True"Background="Transparent",如果你想隐藏整个窗框和建立你自己的。

Update based on code added to question

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

The code you just posted works fine for me. There is no title bar, although there is a Resize border because you specified ResizeMode="CanResize"

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

You do have some whitespace at the top of your window, but that is because you specified a top Margin for your Slider and TextBox (When you specify a Margin with 4 numbers, it goes Left, Top, Right, Bottom so the 2nd number is your Top Margin)

您的窗口顶部确实有一些空白,但那是因为您为 Slider 和 TextBox 指定了一个顶部边距(当您指定一个带有 4 个数字的边距时,它会向左、顶部、右侧、底部移动,因此第二个数字是您的最高保证金)

回答by isakavis

<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>

The above code works fine for your question "How to make title bar dissappear in WPF window?"

上面的代码适用于您的问题“如何使标题栏在 WPF 窗口中消失?”

回答by Iván Boros

try to set the caption height to 0

尝试将标题高度设置为 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>

回答by Sindhu M

Try setting TitleBarHeight="0"

尝试设置 TitleBarHeight="0"

回答by olammy

I think you should play with ShowTitleBar="False" and back anywhere within your application, either in the Xaml file or in the code behind. That should do the trick

我认为您应该使用 ShowTitleBar="False" 并返回应用程序中的任何位置,无论是在 Xaml 文件中还是在后面的代码中。这应该够了吧