web-dev-qa-db-ja.com

WPFウィンドウでタイトルバーを非表示にする方法

私はこれが以前に尋ねられたことを知っていますが、答えを試しました:

どちらも機能せず、タイトルバーのテキストがそこにあり、グリッドをウィンドウの最上部まで移動できないため、グリッドがウィンドウ全体を占有します。これにこだわっています。

ウィンドウの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>
35
Stewart Stoakes

この回答 で説明したように、WindowStyleプロパティをNoneに設定する必要があります。

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

ウィンドウフレーム全体を非表示にして独自のフレームを作成する場合は、AllowsTransparency="True"およびBackground="Transparent"を設定することもできます。

質問に追加されたコードに基づいて更新する

あなたが投稿したコードは、私にとってはうまく機能します。タイトルバーはありませんが、ResizeMode="CanResize"を指定したために境界線のサイズ変更があります

ウィンドウの上部に空白がありますが、それはSliderとTextBoxの上部マージンを指定したためです(4つの数字でMarginを指定すると、左、上、右、下に移動し、2番目の数字があなたのトップマージン)

78
Rachel
<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ウィンドウでタイトルバーを非表示にする方法」という質問に対してうまく機能します。

10
isakavis

キャプションの高さを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
Iván Boros

TitleBarHeight = "0"を設定してみてください

0
Sindhu M