gr-*_*-eg 9 wpf animation xaml
我正在尝试为Skypes通知创建类似的东西,但是我对动画有一些问题.
我希望整个窗口在顶部和底部都有一个边框,然后在中间的内容中用它来"推"边框.我已经设法创造了几乎我想要的东西,但它从顶部向下增长,我希望它能够推动底部边框文具.
我在中间部分使用以下动画,我想出现
<DoubleAnimation
Storyboard.TargetName="contentGrid"
BeginTime="00:00:0.2"
Storyboard.TargetProperty="(FrameworkElement.Height)"
From="0"
Duration="0:0:0.5"/>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢
其余的XAMl:
<Grid Name="notificationPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="contentGrid" Storyboard.TargetProperty="(FrameworkElement.Height)" From="0" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid Grid.Row="0" Background="CornflowerBlue">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Name="notificationTitle" Padding="5" FontSize="14" Foreground="White">
Call Manager - Incoming Call
</TextBlock>
<Path Name="closeButton" Grid.Column="1" Margin="5,10,10,0" Fill="White" Data="F1 M 2.28484e-007,1.33331L 1.33333,0L 4.00001,2.66669L 6.66667,6.10352e-005L 8,1.33331L 5.33334,4L 8,6.66669L 6.66667,8L 4,5.33331L 1.33333,8L 1.086e-007,6.66669L 2.66667,4L 2.28484e-007,1.33331 Z " />
</Grid>
<Grid Name="contentGrid" Grid.Row="1" Background="White" Height="15" VerticalAlignment="Bottom" >
</Grid>
<Rectangle Grid.Row="2" Fill="CornflowerBlue" Height="5" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
您看到的行为由包含您的<Grid Name="notificationPanel">
网格的UIElement确定.
如果将此网格放置在高度设置为"自动"的元素内,则它将从上到下进行动画处理,这不是您想要的.
如果将此网格放置在具有固定高度或高度设置为*的容器内,并且您已将"notificationPanel"网格的VerticalAlignment设置为"Bottom",那么您将获得正确的动画行为, contentGrid'也在成长并向上推动顶部边界,而底部边界保持静止.
关于WPF的其中一件事花了我很长时间才学习:)包含元素通常控制其子元素的行为和/或外观.