在ObjectAnimationUsingKeyFrames中使用TemplateBinding [英] Using TemplateBinding in ObjectAnimationUsingKeyFrames

查看:257
本文介绍了在ObjectAnimationUsingKeyFrames中使用TemplateBinding的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当鼠标悬停在控件上时,我尝试设置控件的背景颜色。我试图通过视觉状态管理器做到这一点。我可以得到以下代码运行:

I try to set the background color of a control when mouse is over it. I try to do it via the visual state manager. I was able to get the following code running:

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Control.Background" Storyboard.TargetName="BorderBackground">
    <DiscreteObjectKeyFrame KeyTime="0">
        <DiscreteObjectKeyFrame.Value>
            <SolidColorBrush Color="#FF123456" />
        </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>

但我不想在模板中设置颜色,控制。我通过以下方式使用'Tag'属性尝试:

But i do not want to set the color in the template, but bind it to a value of the control. I tried it with the 'Tag'-property in the following way:

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Control.Background" Storyboard.TargetName="BorderBackground">
    <DiscreteObjectKeyFrame KeyTime="0">
        <DiscreteObjectKeyFrame.Value>
            <SolidColorBrush Color="{TemplateBinding Tag}" />
        </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>

并将使用此样式的控件的Tag属性设置为'#FF123456'。

and setting the Tag-Property of the control that is using this style to '#FF123456'.

但这不行。它不给我一个错误消息,它只是不改变backgroundcolor。

But this doesn't work. It doesn't left me an error message, it simply doesn't change the backgroundcolor. Anybody knows, what the problem might be?

提前感谢

Frank

Thanks in advance,
Frank

推荐答案

不幸的是,你试图这样做的方式将不能在Silverlight中工作。 VisualStateManager动画不是显示树的一部分,因此不能使用绑定。你有选项,但StaticResources(aka在资源字典中设置颜色)和基于代码的动画是不同的解决方法(取决于你想要做什么)。对于后者,检查一个线程,我问一个类似的问题:如何在Silverlight 4 UserControl中动态动画属性?

Unfortunately the way you're trying to do it won't work in Silverlight. The VisualStateManager animations are not part of the display tree, so you can't use binding. You have options though, StaticResources (aka setting up colours in the resource dictionary) and code based animations are different workarounds (depending on exactly what you want to do). For the latter check out a thread where I asked a similar question: How can I animate a property dynamically in a Silverlight 4 UserControl?

这篇关于在ObjectAnimationUsingKeyFrames中使用TemplateBinding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆