2017-06-29 10 views
1

セットアップ

私は自分のアプリケーションのウィンドウのほとんどに適用される次のスタイルがあります:私はカスタマイズするためにそれを使用WPFボタンのフォーカススタイルが上書きされて

<ResourceDictionary x:Class="MyNamespace.ChromeWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

    <Style x:Key="CustomChromeTest" TargetType="{x:Type Window}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type Window}"> 
        <Grid x:Name="GridMain" Background="{StaticResource MainFormColor}"> 
         <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

を私のウィンドウの周りのウィンドウクロム(私はその部分を削除した)ので、ウィンドウのすべての実際のコンテンツがコンテンツプレゼンターの中に入る。私はそうのように、このスタイルを使用します。

Test window

問題、通常のウィンドウで

、とき:

<Window x:Class="MyNamespace.Window1" 
    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" 
    mc:Ignorable="d" 
    Title="Window1" Height="300" Width="300" 
    Style="{DynamicResource CustomChromeTest}"> 
<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/WPFControlLibrary;component/Resources/ChromeWindow.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 
<StackPanel> 
    <Button Margin="5" Content="Button" Width="75"/> 
    <Button Margin="5" Content="Button" Width="75"/> 
    <Button Margin="5" Content="Button" Width="75"/> 
    <Button Margin="5" Content="Button" Width="75"/> 

</StackPanel> 

は、このXAMLは、上記のようなウィンドウを生成しますユーザーはコントロールをタブで移動しています現在のボタンが強調表示され、ユーザーに現在のボタンが表示されます。下の3番目のボタンの周りに注意してください。

enter image description here

何らかの理由で、私は自分のスタイルを使用し瞬間のために、この機能はを消え、ボタンにも、通常のようなユーザ缶タブものの、フォーカスを持っているの兆候はありません。これはなぜですか、どのようにしての組み込みの機能を復元できますか?

私はウィンドウとコントロールの数百数十人で、このスタイルを使用

に注意してください。コントロールにフォーカスがあるときに境界線を表示するトリガーを使用して、すべてのコントロールでスタイルを使用する必要はありません。カスタムウィンドウスタイルを適用する前に使用されていた既定の機能を復元したい。

答えて

1

ContentPresenterWindowAdornerDecoratorと定義するだけで、意図したとおりに動作します。最初はどちらかといえば明らかに分からなかったもの:

スタイル;

<Style x:Key="CustomChromeTest" TargetType="{x:Type Window}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
     <ControlTemplate TargetType="{x:Type Window}"> 
      <Grid x:Name="GridMain" Background="Yellow"> 
       <AdornerDecorator>      
       <ContentPresenter/> 
       </AdornerDecorator> 
      </Grid> 
     </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

とあなたの窓...

<Window 
     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:WpfApplication1" 
     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
     xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
     xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2" x:Name="Testeroo" 
     x:Class="WpfApplication1.MainWindow" 
     mc:Ignorable="d" Style="{StaticResource CustomChromeTest}" 
     Title="MainWindow" Height="550" Width="750"> 

     <StackPanel> 
      <Button Margin="5" Content="Button" Width="75"/> 
      <Button Margin="5" Content="Button" Width="75"/> 
      <Button Margin="5" Content="Button" Width="75"/> 
      <Button Margin="5" Content="Button" Width="75"/> 
     </StackPanel> 

</Window> 

が、これは、歓声に役立ちます願っています。