动态更改Visual状态DiscreteObjectKeyFrame值

时间:2014-04-21 11:01:44

标签: c# silverlight windows-phone-7 windows-phone-8 windows-phone

我有列表项边框的Visual状态,如下所示:

<VisualStateGroup x:Name="CommonStates">
    <VisualState x:Name="Normal"/>
        <VisualState x:Name="MouseOver">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames
                    Storyboard.TargetName="ListItemBorder"
                    Storyboard.TargetProperty="Background">

                    // how to pass the value to here. 
                    <DiscreteObjectKeyFrame KeyTime="0" Value="#c9vbf2"/>

                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    <VisualState x:Name="Disabled"/>
</VisualStateGroup>

如何更改值c9vbf2。我的AppResources中有价值。

我正在研究WP8

1 个答案:

答案 0 :(得分:1)

你可以像这样引用你的AppResource:

<VisualStateGroup x:Name="CommonStates">
  <VisualState x:Name="Normal"/>
    <VisualState x:Name="MouseOver">
      <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ListItemBorder" Storyboard.TargetProperty="Background">
          <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource YourCustomBrush}" />
        </ObjectAnimationUsingKeyFrames>
      </Storyboard>
    </VisualState>
  <VisualState x:Name="Disabled"/>
</VisualStateGroup>