【问题标题】:prevent the going forward of an icon when I apply a Style on a button in a universal app当我在通用应用程序的按钮上应用样式时防止图标前进
【发布时间】:2016-02-11 17:55:27
【问题描述】:

我在设置 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>

这是我得到的结果:

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

所以请您知道如何更正我的代码以防止在我选择按钮时图标向前移动

感谢帮助

【问题讨论】:

  • 您是否尝试将Padding 调整为负BorderThickness
  • 您的意思是先生要放入样式填充 =-10,0,0,0 ?
  • 如果您的 BorderThickness 为 10:是
  • 感谢先生的回复,现在可以使用了:D
  • 我会为此发布答案。

标签: c# win-universal-app windows-10-universal


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多