开发者

WPF Control Visibility

I have a WPF application and I placed a dock panel over a grid then by default d开发者_高级运维ock panel is Hidden. In the grid I have a button that when I click it the visibility of the dock panel is Visible and I want the dock panel Hidden after 2 seconds. How do I do this?


Try like this

<Window x:Class="WpfApplication30.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Storyboard x:Key="ShowDock">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="dock" Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="00:00:2" Value="{x:Static Visibility.Collapsed}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

    <Grid>
    <Grid>        
        <Button Content="show" Height="30" Width="100">
                <Button.Triggers>
                    <EventTrigger RoutedEvent="Button.Click">
                        <BeginStoryboard Storyboard="{StaticResource ShowDock}"/>
                    </EventTrigger>
                </Button.Triggers>
            </Button>
    </Grid>
        <DockPanel x:Name="dock" Background="Pink" Visibility="Collapsed"/>
    </Grid>
</Window>


I'll assume you want the dock panel to be some sort of popup-and-disappear messagebox:

You could create a storyboard with two animations. The first one an animation that changes the visibility of the dock panel to visible and the second to hidden BUT wit a start time of 2 seconds relative to the start of the storyboard.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜