私のWPFアプリケーション用のカスタムWindowChromeスタイルを持っています(ここからはリッピング:http://www.bdevuyst.com/wpf-custom-title-bar-and-taskbar/)。WindowChrome - タイトルバーのボタンをクリックできません
ここコード:それは非推奨だので、いくつかの理由のために私はタイトルバーのボタンをクリックすることができません:「シェル」
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<!-- Simple style without anything to remove the title bar -->
<Style x:Key="Style.Window.WindowStyleNoneWithTaskbar.Base" TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome" >
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="0" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="1" >
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Simple style with system buttons upper right -->
<Style TargetType="{x:Type Window}" BasedOn="{StaticResource Style.Window.WindowStyleNoneWithTaskbar.Base}" x:Key="Style.Window.WindowStyleNoneWithTaskbar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="1">
<Grid>
<ContentPresenter
Content="{TemplateBinding Content}" />
<Canvas Grid.Column="2" HorizontalAlignment="Right" Margin="0,6,10,0" VerticalAlignment="Top" >
<Button x:Name="MinimizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" Width="24" Height="24" Canvas.Right="55" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close" >
<Rectangle Margin="2" Fill="{DynamicResource appbar.reduce}" Opacity=".5" Width="15" Height="15" />
</Button>
<Button x:Name="NormalizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Visibility="Collapsed" Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}" Width="24" Height="24" Canvas.Right="30" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Restore" >
<Rectangle Margin="2" Fill="{DynamicResource appbar.normal}" Opacity=".5" Width="15" Height="15" />
</Button>
<Button x:Name="MaximizeButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}" Width="24" Height="24" Canvas.Right="30" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Maximize" >
<Rectangle Margin="2" Fill="{DynamicResource appbar.maximize}" Opacity=".5" Width="15" Height="15" />
</Button>
<Button x:Name="CloseButton" Style="{DynamicResource Style.Button.Core.Transparent}" Command="{Binding Source={x:Static SystemCommands.CloseWindowCommand}}" Width="24" Height="24" Canvas.Right="5" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close" >
<Rectangle Margin="2" Fill="{DynamicResource appbar.close}" Opacity=".5" Width="15" Height="15" />
</Button>
</Canvas>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="WindowState" Value="Maximized">
<Setter Property="Visibility" Value="Collapsed" TargetName="MaximizeButton" />
<Setter Property="Visibility" Value="Visible" TargetName="NormalizeButton" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
私はへの参照を削除しました。私はリンクされたウェブサイトからサンプルのソリューションをダウンロードし、ボタンは私から働いた。
次に、「シェル」バックへの参照を追加しましたが、まだボタンをクリックできませんでした。
ここで間違っていることはわかりません。私はかなり完全に私のプロジェクトにサンプルソリューションをコピーしたとまだは動作しませんでした。 IsHitTestVisibleInChromeを各ボタンの "true"に設定しましたが、違いはありません。
私は基本的なボタンとスタイリングなしで、他のいくつかの、もっと簡単なアプローチを試しましたが、役に立たないものです。ここで明白な何かが欠けているような気がする。
応答をいただき、ありがとうございます。私は今夜家に帰るときにこれを試してみよう。 –
それを修正した。また、私はコードビハインドコマンドバインディングを追加しませんでした。私はViewModelでそれをするのに慣れています。ありがとう! –