簡體   English   中英

如何在wp8中將動畫添加到網格

[英]How to add animation to grid in wp8

我有一個網格控件。在按鈕上單擊,此網格將可見。在后端代碼中,我在按鈕單擊中向網格中添加了子元素。我希望此網格以特定的樣式加載並帶有特定的動畫。 請提出解決方案

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

您可以為網格創建一個情節提要

樣品

<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/zh-cn/library/windowsphone/develop/jj206955(v=vs.105).aspx

借助Blend可以很好地創建情節提要。請參閱: http : //msdn.microsoft.com/zh-cn/library/windows/apps/jj129478.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM