【问题标题】:UWP - change background color of buttonUWP - 更改按钮的背景颜色
【发布时间】:2016-07-04 15:04:34
【问题描述】:

我想在所有情况下更改按钮的默认背景。但是当我使用时

button.Background = new SolidColorBrush(Windows.UI.Colors.Red);

如果按下按钮,我会得到一个红色按钮和灰色按钮。 我想我必须改变一种按钮的风格。但是如何设置样式中的颜色呢?

<VisualState x:Name="Pressed">
<Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseHighBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <PointerDownThemeAnimation Storyboard.TargetName="RootGrid" />
</Storyboard>

【问题讨论】:

    标签: c# button background styles win-universal-app


    【解决方案1】:

    你有这个动画:

    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}" />
    </ObjectAnimationUsingKeyFrames>
    

    您可以看到它在按下时将 RootGrid 的 Background 属性设置为 {ThemeResource SystemControlBackgroundBaseMediumLowBrush} 值。只需将其替换为您的颜色即可:

    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
        <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
    </ObjectAnimationUsingKeyFrames>
    

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 1970-01-01
      • 2018-06-19
      • 2015-06-04
      • 1970-01-01
      • 2021-06-22
      • 2015-04-03
      相关资源
      最近更新 更多