如何让标题栏在WPF窗口中消失?

时间:2013-03-14 15:20:49

标签: wpf xaml window titlebar

我知道之前有人问过,但我已经尝试过答案了:

并且都不起作用,标题栏文本就在那里,我无法将我的网格移动到窗口的顶部,以便网格占据整个窗口。我坚持这个。

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

5 个答案:

答案 0 :(得分:76)

您需要将WindowStyle属性设置为None,就像我在this answer

中概述的那样
<Window ...
    WindowStyle="None"
    WindowState="Maximized"
    WindowStartupLocation="CenterScreen">

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

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

您发布的代码对我来说很合适。虽然有一个Resize边框,但没有标题栏,因为您指定了ResizeMode="CanResize"

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

答案 1 :(得分:9)

<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窗口中使标题栏消失?”

答案 2 :(得分:0)

尝试设置TitleBarHeight =“ 0”

答案 3 :(得分: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>

答案 4 :(得分:-1)

我认为你应该玩ShowTitleBar =&#34; False&#34;并返回应用程序中的任何位置,可以是Xaml文件,也可以是后面的代码。那应该是诀窍

相关问题