DynamicResource颜色不工作 [英] DynamicResource color not working

查看:253
本文介绍了DynamicResource颜色不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

<Color x:Key="SelectedColor">Gold</Color> 

和包含颜色的TabItem风格

And a TabItem Style that contains the color

<VisualState x:Name="Selected">
    <Storyboard>
        <ColorAnimationUsingKeyFrames 
            Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
            Storyboard.TargetName="InnerRectangle2">
            <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource SelectedColor}"/>
        </ColorAnimationUsingKeyFrames>

原来我不能使用 DynamicResource 上的 EasingColorKeyFrame
我能做些什么来实现我的效果呢?

It turns out I can't use a DynamicResource on an EasingColorKeyFrame.
What can I do to achieve my effect?

我需要动态设置颜色,所以才换{DynamicResource SelectedColor}{的StaticResource SelectedColor}是假表。

I need to set the color dynamically, so just swapping "{DynamicResource SelectedColor}" with "{StaticResource SelectedColor}" is off the table.

我创建了一个微小的解决方案来说明问题 - 所选标签应该是金色的,但实际上它是透明的,因为我想VSM不能解决命名为颜色 SelectedColor

I've created a tiny solution to demonstrate the problem - the Selected Tab should be Gold colored, but it's actually transparent, because I guess the VSM can't resolve the color named "SelectedColor"

http://dl.dropbox.com/u/10557283/DynamicBug.zip

推荐答案

我想出了一个办法,层次做到这一点。让你的对象的多个副本,然后只修改透明胶片是这样的:

I figured out a way to do it with layers. Make multiple copies of your object, and then just modify the transparencies like this:

<VisualState x:Name="Selected">
    <Storyboard>
        <DoubleAnimation Storyboard.TargetName="InnerRectangleBorder"
                         Storyboard.TargetProperty="Opacity"
                         To="0"
                         Duration="0:0:0" />

        <DoubleAnimation Storyboard.TargetName="InnerRectangleBorderMouseOver"
                         Storyboard.TargetProperty="Opacity"
                         To="0"
                         Duration="0:0:0.5" />

        <DoubleAnimation Storyboard.TargetName="InnerRectangleBorderSelected"
                         Storyboard.TargetProperty="Opacity"
                         To="1"
                         Duration="0:0:1" />
    </Storyboard>
</VisualState>

这篇关于DynamicResource颜色不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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