How to make title bar disappear in WPF window?

后端 未结 5 1159
刺人心
刺人心 2020-12-25 10:24

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

  • How to create a WPF Window without a border that can be resized via a grip only?
  • How to rem
相关标签:
5条回答
  • 2020-12-25 10:34
    <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?"

    0 讨论(0)
  • 2020-12-25 10:39

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

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

    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"

    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)

    0 讨论(0)
  • 2020-12-25 10:44

    Try setting TitleBarHeight="0"

    0 讨论(0)
  • 2020-12-25 10:52

    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

    0 讨论(0)
  • 2020-12-25 10:58

    try to set the caption height to 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>
    

    0 讨论(0)
提交回复
热议问题