2012-12-07 62 views
1

我想禁用(全局)的FocusVisualStyleKey。如何禁用(全局)的FocusVisualStyleKey

我在寻找一个可能性,我没有把任何元素的下面的代码:

<Style TargetType="ToggleButton"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 

所以我读这article,并发现此解决方案:

的App.xaml

<Application x:Class="WpfApplication7.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
     <Style x:Key="{x:Static SystemParameters.FocusVisualStyleKey}"> 
      <Setter Property="Control.Template"> 
       <Setter.Value> 
        <ControlTemplate> 
         <Rectangle StrokeThickness="0" SnapsToDevicePixels="true" /> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Application.Resources> 
</Application> 

MainWindow.xaml

<Window x:Class="WpfApplication7.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"> 
    <Window.Resources> 
    </Window.Resources> 
    <Grid> 
     <Button Content="Button" HorizontalAlignment="Left" Margin="98,230,0,0" VerticalAlignment="Top" Width="75"/> 
     <Button Content="Button" HorizontalAlignment="Left" Margin="217,230,0,0" VerticalAlignment="Top" Width="75"/> 
     <Button Content="Button" HorizontalAlignment="Left" Margin="368,230,0,0" VerticalAlignment="Top" Width="75"/> 
     <ComboBox HorizontalAlignment="Left" Margin="40,40,0,0" VerticalAlignment="Top" Width="150" Height="40"/> 
     <ComboBox HorizontalAlignment="Left" Margin="317,40,0,0" VerticalAlignment="Top" Width="150" Height="40"/> 
    </Grid> 
</Window> 

但它不起作用... 有没有人有另一种想法?

+0

这不是对每个控制重点的视觉风格。例如按钮采用与关键ButtonFocusVisual一种风格,而组合框使用一个名为ComboBoxFocusVisual – Dtex

回答

0

是的,有一种方法可以做到这一点,但你不会喜欢它。首先再拍XAML字典。在它定义在航空各控制或W/E为主题的风格,你正在使用,然后将支持算法FMP属性为隐含的关键。

例如

<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"> 

然后创建一个setter为FocusVisualStyle

<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
</Style> 

注意:您要为每一个控制做到这一点。

下一页合并新主题字典转为Window.Resources

<Window.Resources> 
    <ResourceDictionary Source="[your dictionary]"/> 
</Window.Resources>