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

Ste*_*kes 35 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>
Run Code Online (Sandbox Code Playgroud)

Rac*_*hel 79

你需要将WindowStyle属性设置为None,就像我在这个答案中概述的那样

<Window ...
    WindowStyle="None"
    WindowState="Maximized"
    WindowStartupLocation="CenterScreen">
Run Code Online (Sandbox Code Playgroud)

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

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

您发布的代码对我来说很好.虽然有指定的Resize边框,但没有标题栏ResizeMode="CanResize"

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


isa*_*vis 10

<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>
Run Code Online (Sandbox Code Playgroud)

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

  • 设置 AllowsTransparency="True" 并设置 borderbrush 和 borderthickness。这将显示边界。WindowStyle="None" ResizeMode="CanResize" AllowsTransparency="True" BorderThickness="1" BorderBrush="Black" (2认同)

小智 5

尝试将标题高度设置为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>
Run Code Online (Sandbox Code Playgroud)


小智 5

<Window  WindowStyle="None" >
Run Code Online (Sandbox Code Playgroud)

将删除窗口的标题栏,

如果您只想在窗口中添加一个标题,您可以在其中拖动移动,只需为标题创建一个网格行

在此输入图像描述

这是我用来制作页面标题的代码

xaml

    <Grid Grid.Row="0" Background="#FF486A9B"    MouseDown="Window_MouseDown"  >
Run Code Online (Sandbox Code Playgroud)

C#

   private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ChangedButton == MouseButton.Left)
            this.DragMove();
    }





  
Run Code Online (Sandbox Code Playgroud)