当我在通用应用程序的按钮上应用样式时阻止图标前进

prevent the going forward of an icon when I apply a Style on a button in a universal app

我在设置 SplitView 菜单的图像图标样式时遇到问题,例如 Groove 应用程序菜单,这是我的代码:

<Style  x:Key="ButtontopStyleGroove"
        TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                   Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="transparent" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentPresenter x:Name="ContentPresenter"
                          BorderBrush="#393185"
                          Content="{TemplateBinding Content}"
                          />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

这是我得到的结果:

问题是当我点击按钮应用我定义的样式时,图标前进,因为我在样式中添加了边框

所以请你知道如何更正我的代码以防止当我 select 按钮

时图标继续前进

感谢帮助

这里的问题是边框不可见时没有粗细。当它变得可见时,整个客户区域将被移动(并且可能被裁剪)space 现在需要绘制边框(也称为厚度)的量。

为避免移动,您可以将填充更改为负边框厚度。这样,边框粗细将内容向右移动,而内容向左移动。这导致根本没有移动。