开发者

Set visibility with a trigger

开发者 https://www.devze.com 2023-03-26 19:36 出处:网络
I just want to start an storyboard which makes an rectangle visible for 2 seconds when user pressed with left mouse button. But I could not solve how to get the visibility value.

I just want to start an storyboard which makes an rectangle visible for 2 seconds when user pressed with left mouse button. But I could not solve how to get the visibility value.

<Grid.Triggers>
            <EventTrigger RoutedEvent="MouseDown"  >
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Duration="0:0:2" Storyboard.TargetName="RectFront" Storyboard.TargetProperty="Visibility">
                                <LinearDoubleKeyFrame KeyTime="0:0:0.100" Value="1" />
           开发者_如何转开发                     <LinearDoubleKeyFrame KeyTime="0:0:2" Value="0" /> <---   HOW to change this into Visibility Type?
                            </DoubleAnimationUsingKeyFrames>

                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </Grid.Triggers>


For example:

Value="{x:Static Visibility.Hidden}"

but in some cases the XAML parser can just convert a normal string like Value="Hidden" as well.

A problem here is though that to animate Visibility you cannot use a DoubleAnimationUsingKeyFrames, it has to be an ObjectAnimationUsingKeyFrames.

If you want to animate visibility gradually you can use a DoubleAnimation (with or without keyframes) but you need to target the Opacity instead.

0

精彩评论

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