【问题标题】:Silverlight: Changing the Background-Brush on MouseOverSilverlight:更改 MouseOver 上的背景画笔
【发布时间】:2010-12-21 00:59:35
【问题描述】:

在我的 Silverlight 应用程序中,我想在鼠标悬停时更改按钮的背景画笔。我为我的按钮制作了一个样式并更改了 MouseOver-VisualState:

<VisualState x:Name="MouseOver">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Background)" Storyboard.TargetName="BorderBackground">
        <DiscreteObjectKeyFrame KeyTime="0">
            <DiscreteObjectKeyFrame.Value>
                <Background>{TemplateBinding BorderBrush}</Background>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

这不起作用,因为名称空间“http://schemas.microsoft.com/client/2007”中不存在名称“背景”。知道吗,如何在鼠标悬停时将 Background-Brush 设置为 Border-Brush 而无需使用后面的代码和适当的事件?

提前致谢,
弗兰克

【问题讨论】:

    标签: silverlight animation


    【解决方案1】:

    BackgroundControl 而不是 UIElement 的属性,这就是它不起作用的原因。

    Source

    您需要使用以下内容:

    ... Storyboard.TargetProperty="(Control.Background)" ...
    

    【讨论】:

    • 感谢您的回复!不幸的是,它仍然告诉我名称空间“schemas.microsoft.com/client/2007"”中不存在名称“背景”。 (窃听行是 {TemplateBinding BorderBrush} 行,顺便说一句。)如果我明确输入 {TemplateBinding BorderBrush} 它告诉我,嵌套属性不是支持
    • 这整件事不起作用,因为我不能在 VisualStateManager 中使用绑定。
    【解决方案2】:

    它不起作用,因为我无法在 VisualStateManager 中使用 Binding,如下所述:Using TemplateBinding in ObjectAnimationUsingKeyFrames

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 2011-01-17
      • 2011-02-02
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多