如何在wp8中将动画添加到网格中

本文关键字:添加 网格 动画 wp8 | 更新日期: 2023-09-27 17:57:56

我有一个网格控件。点击按钮,这个网格就会可见。在后台代码中,我在按钮点击中添加了子元素到网格中。我希望这个网格以特定的模式加载,并带有特定的动画。请建议的解决方案

<Grid x:Name="menuholder" Height="Auto" Canvas.ZIndex="1" 
      Grid.RowSpan="5" HorizontalAlignment="Right" 
      VerticalAlignment="Top" Margin="0,0,15,0">
</Grid>

在后端:

MenuUserControl menu = new MenuUserControl();
menu.Visibility = Visibility.Visible;
menu.HorizontalAlignment = HorizontalAlignment.Left;
menu.VerticalAlignment = VerticalAlignment.Top;
menu.Width = 200;
menuholder.Children.Add(menu);
menuholder.Visibility = Visibility.Visible;
isMenuVisible = false;
Canvas.SetZIndex(menu, 2);

如何在wp8中将动画添加到网格中

您可以为网格创建情节提要

样品

<phone:PhoneApplicationPage
    x:Class="TestApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid x:Name="grdAnimated" Background="Red" HorizontalAlignment="Right" Height="100" Width="200">
                <Grid.Resources>
                    <Storyboard x:Name="grdStoryBoard">
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grdAnimated">
                            <EasingDoubleKeyFrame KeyTime="0" Value="900"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </Grid.Resources>
                <Grid.RenderTransform>
                    <CompositeTransform TranslateY="900" />
                </Grid.RenderTransform>
            </Grid>
        </Grid>
   </Grid>
</phone:PhoneApplicationPage>

在您的xaml.cs代码中

在你的按钮上开始Storyborad操作,如:

grdStoryBoard.Begin();

您可以相应地更改动画类型参考:http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206955(v=vs.105).aspx

情节板可以在Blend的帮助下很好地创建参考:http://msdn.microsoft.com/en-us/library/windows/apps/jj129478.aspx