有没有关于如何创建那种在Web应用程序中使用的(通常是黄色的)弹出式动画横幅的指针(例如stackoverflow FAQ)?
我很想回答“使用jQuery”,但由于这是WPF,我认为需要更好的东西。首先,我将定义在xaml文件中bar所在的位置。我会像这样做:
<Window ...>
<Grid>
<Grid x:Name="DropDownBar" HorizontalAlignment="Stretch" Height="0">
<Rectangle Fill="Orange" />
</Grid>
<!-- rest of your content here -->
</Grid>
</Window>
<Window.Resources>
<Storyboard x:Key="LoadAnimation" Duration="0:0:3">
<DoubleAnimation Storyboard.TargetName="DropDownBar" Storyboard.TargetProperty="Height" From="0" To="30" />
</Storyboard>
</Window.Resources>
然后你只需要在页面加载时触发它:
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard Storyboard="{StaticResource LoadAnimation}" />
</EventTrigger>
</Window.Triggers>
我在这个框中打字,所以难免会有一些错别字。但基本上我会这样做。另一种选择是固定高度,并将边距从 -height 移动到 0。