質問

I want to disable (globally) the FocusVisualStyleKey.

I'm looking for a possibility, that I have not put on any element the following code:

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

So I read this article, and found this solution:

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>

But it doesn't work... Does anyone have another idea?

役に立ちましたか?

解決

Yes, there is a way to do this but you are not going to like it. First make another xaml dictionary. In it define a style for each control in Aero or w/e theme you're using, then set BasedOn property to implicit key.

example

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

then create a setter for FocusVisualStyle

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

Note: you'll have to do this for EVERY control.

Next merge your new themes dictionary into Window.Resources

<Window.Resources>
    <ResourceDictionary Source="[your dictionary]"/>
</Window.Resources>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top