【问题标题】:WPF: In Expression Blend, how to change Foreground of a custom button with a Border on different states?WPF:在 Expression Blend 中,如何更改具有不同状态的边框的自定义按钮的前景?
【发布时间】:2013-06-25 04:30:43
【问题描述】:

在 Expression Blend 4 中,我想在不同状态下更改自定义按钮的 Foreground。我只能更改BackgroundBorderBrush

就像这样:

如果状态为“Normal”,文本“Button”的颜色为Black,而状态为“Pressed”,文本“Button”的颜色为White

Brushes PanelProperties Panel 上有3 个属性,但没有Foreground 属性:

谁能帮帮我?我很困惑。

编辑

我发现ContentControl 有一个Foreground 属性,但ContentPresenter 没有。我应该使用ContentControl而不是ContentPresenter吗?

【问题讨论】:

    标签: wpf templates styles expression-blend


    【解决方案1】:

    到目前为止,我还没有找到通过 Blend 更改 Foreground 的方法(我的意思是不在代码中)。在代码中,就像这样:

    <ResourceDictionary ...>
    
        <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="Template">
                ...
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        ...
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ColorAnimationUsingKeyFrames 
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
                                    <EasingColorKeyFrame KeyTime="0" Value="Blue"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        ...
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
    
                <ContentPresenter .../>
                ...
    </ResourceDictionary>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 2017-03-24
      • 1970-01-01
      • 2014-06-21
      相关资源
      最近更新 更多