【问题标题】:Changing Button Foreground using VisualStateManager in uwp在 uwp 中使用 VisualStateManager 更改按钮前景
【发布时间】:2016-06-14 13:55:47
【问题描述】:

我尝试使用视觉状态管理器更改按钮的前景色,但它根本不起作用。

   <Button x:Name="Close" HorizontalAlignment="Stretch" 
                                            Width="100" Background="#FF4F4F4F" 
                                            Height="50" BorderThickness="2" BorderBrush="#FF2F2F2F"
                                            Content="Cancel">
                                        <VisualStateManager.VisualStateGroups>
                                            <VisualStateGroup x:Name="CommonStates">
                                                <VisualState x:Name="PointerOver">
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Close"
                                                                   Storyboard.TargetProperty="Foreground">
                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#FFFFFFFF" />
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </VisualState>
                                                <VisualState x:Name="Pressed">
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Close"
                                                                   Storyboard.TargetProperty="Foreground">
                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#FFFFFFFF" />
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </VisualState>
                                            </VisualStateGroup>
                                        </VisualStateManager.VisualStateGroups>
                                    </Button>

请帮我解决这个问题。

提前致谢。

【问题讨论】:

  • 如果改为在控件模板中进行是否有效?

标签: c# xaml uwp-xaml


【解决方案1】:

它不起作用,因为您试图为画笔类型设置颜色值。

请使用您需要的颜色创建一个 Brush StaticResource。并在动画中设置资源。

<SolidColorBrush x:Key="TextBoxErrorThemeBrush" Color="Red" />

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PART_TextBlock">
     <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxErrorThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>

问候,

杰西

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2022-01-16
    • 2017-12-29
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多