2017-03-23 20 views
0

デフォルトのキャプションボタンとタイトルバーを使用してウィンドウを作成しようとしていて、ウィンドウクロム内に任意のコンテンツを配置できるようにしようとしています。しかし、私が試したすべてのソリューションはキャプションボタンの右側に約5単位の余白を残しています。ここで基本的な例である:通常のキャプションボタンで非クライアント領域にコンテンツを正しく描画する方法

<Window x:Class="SemiCustomWindowChrome.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:SemiCustomWindowChrome" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525" Name="Window"> 
<WindowChrome.WindowChrome> 
    <WindowChrome UseAeroCaptionButtons="True" ResizeBorderThickness="5" GlassFrameThickness="1,28,1,1"/> 
</WindowChrome.WindowChrome> 
<Window.Template> 
    <ControlTemplate> 
     <AdornerDecorator> 
      <ContentPresenter Content="{Binding ElementName=Window, Path=Content}"/> 
     </AdornerDecorator> 
    </ControlTemplate> 
</Window.Template> 
<Grid> 
    <StackPanel Orientation="Horizontal" VerticalAlignment="Top"> 
     <Button Content="Click me daddy!" WindowChrome.IsHitTestVisibleInChrome="True" Height="28"/> 
     <TextBlock Text="Custom Window Test" Margin="6.5"/> 
    </StackPanel> 
    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontFamily="MS Calibri" FontWeight="ExtraLight" Text="Hello There"/> 
</Grid> 

上記のコードはthisを生成します。

明確にするために、ウィンドウクロムのキャプションボタンの右側にある白いパディングを削除して、ウィンドウが他のものとまったく同じになるようにしたいと思います。非クライアント領域(ウィンドウクロム)。 すべてのサポートが高く評価されています。

WindowChrome要素の使用を含まないDWMでもっと安定した方法がある場合は、誰かが私に例を挙げることができたらうれしいです。

答えて

0
WindowChrome.WindowChrome> 
    <WindowChrome GlassFrameThickness="0.5,28,0,0.5" NonClientFrameEdges="Right"/> 
</WindowChrome.WindowChrome> 
<Window.Template> 
    <ControlTemplate> 
     <ContentPresenter Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Content}"/> 
    </ControlTemplate> 
</Window.Template> 

これは検索に非常に時間がかかりました。もともと、私はWindowChromeクラスがちょうど完全に壊れていると思っていましたが、それはある程度ですが、とにかくそれを使用することができました。私が思いついた他の解決策は、はるかに複雑で、最終的には、WindowChromeを試してみるだけでもっと簡単に思えました。私は特にWindows 10用のクラスの修正版で作業しますが、それまではこれが動作します。これが誰かに役立つことを願っています。

このコードを使用するには、ウィンドウのXAMLのコンテンツ領域の上部に配置します。

関連する問題