Silverlight: adding a visual transition between visible and invisible states

I would like to add a visual effect (such as fading, fading) on ​​a control whose visibility may change.

I don’t know where to start doing this. I read a little about VisualStateManager and VisualTransform, but I still don't know if this is possible and what to do. Can you help me?

thank

+5
source share
1 answer

What you want is possible.

You need VisualStateManagerone that defines ShowStatea HideState. They, in turn, determine Storyboardwhich controls the visibility.

Then you call

VisualStateManager.GoToState(uiElement, "ShowState", true);

, "ShowState" . "HideState" .

XAML VisualStateManager. , /.

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStates">
            <VisualState x:Name="ShowState">
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
                                                   Storyboard.TargetProperty="(UIElement.Opacity)">
                        <EasingDoubleKeyFrame KeyTime="00:00:01"
                                              Value="1" />
                    </DoubleAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
                                                   Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                            <DiscreteObjectKeyFrame.Value>
                                <Visibility>Visible</Visibility>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="HideState">
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
                                                   Storyboard.TargetProperty="(UIElement.Opacity)">
                        <EasingDoubleKeyFrame KeyTime="00:00:01"
                                              Value="0" />
                    </DoubleAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
                                                   Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:01">
                            <DiscreteObjectKeyFrame.Value>
                                <Visibility>Collapsed</Visibility>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

KeyTime . , , "HideState" 0, , . AnthonyWJones !

+6

All Articles