从 Windows 10 Core - XAML 上的按钮移除焦点

Remove focus from button on Windows 10 Core - XAML

我有一个带有背景图片和白色文本的按钮。 当我单击它或将鼠标放在(焦点)上时,显示黑色边框并且文本保持黑色。 我该怎么做才能忽略鼠标悬停并在按下时呈现点击视觉效果?

已经添加但是没有效果。

<Style x:Key="ButtonActionStyle" TargetType="Button">
    ...
    <Setter Property="UseLayoutRounding" Value="False"/>
    <Setter Property="UseSystemFocusVisuals" Value="False"/>
</Style>

谢谢


这段代码做了我需要的,但是没有点击视觉效果:x

<Style x:Key="ButtonActionStyle" TargetType="Button">
    ...
    <Setter Property="UseLayoutRounding" Value="False"/>
    <Setter Property="UseSystemFocusVisuals" Value="False"/>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Row)" Storyboard.TargetName="grid">
                                        <DiscreteObjectKeyFrame KeyTime="1">
                                            <DiscreteObjectKeyFrame.Value>
                                                <x:Int32>1</x:Int32>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="PointerOver"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid>
                        <Grid x:Name="grid" Margin="0" Grid.Row="0" Grid.RowSpan="1">
                            <Border
                                BorderBrush="{TemplateBinding Background}"
                                BorderThickness="0"
                                CornerRadius="0"
                                Background="{TemplateBinding Background}"/>
                            <ContentPresenter>
                                <TextBlock
                                   FontFamily="{TemplateBinding FontFamily}"
                                    SelectionHighlightColor="{TemplateBinding Foreground}"
                                    FontSize="{TemplateBinding FontSize}"
                                    Foreground="{TemplateBinding Foreground}"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Height="Auto"
                                    Width="Auto"
                                    Text="{Binding Content, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            </ContentPresenter>
                        </Grid>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

根据this教程,完成。

<Style x:Key="ButtonActionStyle" TargetType="Button">
    ...
    <Setter Property="UseLayoutRounding" Value="False"/>
    <Setter Property="UseSystemFocusVisuals" Value="False"/>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="PointerOver"/>
                            <VisualState x:Name="Pressed">
                                <VisualState.Setters>
                                    <Setter Target="grid.(Grid.Row)" Value="0"/>
                                    <Setter Target="grid.(Canvas.ZIndex)" Value="0"/>
                                    <Setter Target="grid.(UIElement.RenderTransformOrigin)">
                                        <Setter.Value>
                                            <Foundation:Point>0.5,0.5</Foundation:Point>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Target="grid.(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Value="1"/>
                                    <Setter Target="grid.(UIElement.Projection).(PlaneProjection.LocalOffsetX)" Value="5"/>
                                    <Setter Target="grid.(UIElement.Projection).(PlaneProjection.LocalOffsetY)" Value="5"/>
                                    <Setter Target="grid.(UIElement.Projection).(PlaneProjection.LocalOffsetZ)" Value="0"/>
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid>
                        <Grid x:Name="grid" Margin="0" Grid.Row="0" Grid.RowSpan="1">
                            <Grid.Projection>
                                <PlaneProjection/>
                            </Grid.Projection>
                            <Grid.RenderTransform>
                                <CompositeTransform/>
                            </Grid.RenderTransform>
                            <Border
                                BorderBrush="{TemplateBinding Background}"
                                BorderThickness="0"
                                CornerRadius="0"
                                Background="{TemplateBinding Background}"/>
                            <ContentPresenter>
                                <TextBlock
                                    FontFamily="{TemplateBinding FontFamily}"
                                    SelectionHighlightColor="{TemplateBinding Foreground}"
                                    FontSize="{TemplateBinding FontSize}"
                                    Foreground="{TemplateBinding Foreground}"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Height="Auto"
                                    Width="Auto"
                                    Text="{Binding Content, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            </ContentPresenter>
                        </Grid>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>