我有一个网格控件。在按钮上单击此网格将是可见的。在后端代码中,我在按钮单击中将子元素添加到网格。我希望此网格以特定模式加载某些动画。请提出解决方案
<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);
答案 0 :(得分: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/en-us/library/windowsphone/develop/jj206955(v=vs.105).aspx
在Blend的帮助下可以很好地创建故事板 请参阅:http://msdn.microsoft.com/en-us/library/windows/apps/jj129478.aspx