gpt4 book ai didi

c# - WPF 控件可见性

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:25 26 4
gpt4 key购买 nike

我有一个 WPF 应用程序,我在网格上放置了一个停靠面板,然后默认情况下停靠面板是隐藏的。在网格中,我有一个按钮,当我单击它时,停靠面板的可见性是可见的,我希望停靠面板在 2 秒后隐藏。我该怎么做?

最佳答案

这样试试

<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>

关于c# - WPF 控件可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6812194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com