1

我想(全局)禁用 FocusVisualStyleKey。

我正在寻找一种可能性,即我没有在以下代码中添加任何元素:

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

所以我读了这篇文章,找到了这个解决方案:

应用程序.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>

主窗口.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>

但它不起作用......有人有其他想法吗?

4

1 回答 1

0

是的,有一种方法可以做到这一点,但你不会喜欢它。首先制作另一个 xaml 字典。在其中为您使用的 Aero 或 w/e 主题中的每个控件定义一个样式,然后将 BasedOn 属性设置为隐式键。

例子

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

然后为 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>
于 2012-12-09T06:05:11.990 回答