开发者

How do I create a property of a user control to control the value of a storyboard keyframe?

开发者 https://www.devze.com 2023-04-01 20:29 出处:网络
As an intro to User Controls, I\'m trying to create an LED User Control. When adding the LEDControl to my xaml, I want to be able to specify the color of the LED, LEDColor.I\'ve added two storyboards

As an intro to User Controls, I'm trying to create an LED User Control. When adding the LEDControl to my xaml, I want to be able to specify the color of the LED, LEDColor. I've added two storyboards to the LED, TurnOn, and TurnOff, that animate the Rectangle fill color between 'off' (grey) and 'on' (LEDColor).

How do I dynamically specify the color that the the storyboard will use for the 'To' value?

Note, I am using Silverlight for Windows Phone. At this point, I'm targetting wp7 but open to Mango soltions if it 开发者_高级运维makes it more sense.


Very simply, you just set the value like you set any other with a storyboard.

Here I've used a {StaticResource LEDColor} for the colour. Just bear in mind, it needs to be a Brush, and not a Color.

It's modifying a Rectagle named LEDControl and have a 0.5 second animation time.

<Storyboard x:Name="TurnOn">
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="LEDControl">
        <DiscreteObjectKeyFrame KeyTime="0" Value="Grey"/>
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="LEDControl">
        <DiscreteObjectKeyFrame KeyTime="0.5" Value="{StaticResource LEDColor}"/>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Name="TurnOff">
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="LEDControl">
        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LEDColor}"/>
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="LEDControl">
        <DiscreteObjectKeyFrame KeyTime="0.5" Value="Grey"/>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>


You May have to be more precise when asking questions.

but if your talking about what i think you are, you should be able to change the state with the storyboard action so when that storyboard action is called it will also Change the fill color.

so when your recording the action for the StoryBoard, on the ON StoryBoard also change the color in the properties panel.

This is of course if your using Blend 4.

0

精彩评论

暂无评论...
验证码 换一张
取 消