WPF按钮焦点样式在放置到content presenter中时被覆盖 设置

WPF按钮焦点样式在放置到content presenter中时被覆盖 设置,wpf,xaml,contentpresenter,Wpf,Xaml,Contentpresenter,我的应用程序中的大多数窗口都采用了以下样式: <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" Targ

我的应用程序中的大多数窗口都采用了以下样式:

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

我用它来定制我的窗口周围的chrome窗口(我已经移除了那个部分),这样窗口的所有实际内容都会进入内容展示器。我是这样使用这种风格的:

<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生成的窗口如下所示:

问题 在普通窗口中,当用户在控件间切换时,当前按钮高亮显示,以向用户显示当前按钮。注意下面第三个按钮周围的边框

出于某种原因,当我使用我的样式时,该功能消失了,并且没有显示哪个按钮具有焦点,即使用户可以像正常一样进行制表。这是为什么?如何恢复内置功能

请注意
我使用这种风格,有几十个窗口和数百个控件。我不希望在每个控件上使用一种样式,该样式带有一个触发器,在控件具有焦点时显示边框。我想恢复在应用自定义窗口样式之前使用的默认功能。

您只需将
内容演示器定义为
窗口的
装饰器
,它就可以正常工作了。我一开始也没有弄明白,显然:)

风格

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

希望这有帮助,干杯