1
我想爲RowDefinition製作一個改變高度的故事板,並且我發現this可以幫助我。當我想創建類GridLengthAnimation,我不能使它成爲一個AnimationTimeline的唯一問題。這是因爲Windows Phone 8不支持這個嗎?故事板定位GridLength for WP8
在這種情況下,是否有另一個解決RowDefinition故事板的工作?
我想爲RowDefinition製作一個改變高度的故事板,並且我發現this可以幫助我。當我想創建類GridLengthAnimation,我不能使它成爲一個AnimationTimeline的唯一問題。這是因爲Windows Phone 8不支持這個嗎?故事板定位GridLength for WP8
在這種情況下,是否有另一個解決RowDefinition故事板的工作?
最簡單的方法可能是您將網格放入行中,並像這樣爲它們的Height屬性設置動畫效果。
這裏是XAML:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Background="AliceBlue"
Grid.Row="0"
Height="100"
Tap="Grid_Tap"
CacheMode="BitmapCache" />
<Grid Background="AntiqueWhite"
Grid.Row="1"
Height="100"
Tap="Grid_Tap"
CacheMode="BitmapCache" />
<Grid Background="Aqua"
Grid.Row="2"
Height="100"
Tap="Grid_Tap"
CacheMode="BitmapCache" />
<Grid Background="Aquamarine"
Grid.Row="3"
Height="100"
Tap="Grid_Tap"
CacheMode="BitmapCache" />
</Grid>
和CS:
private void AnimateHeight(Grid grid)
{
double newHeight = grid.ActualHeight == 100 ? 300 : 100; //select the height we want to animate
Storyboard story = new Storyboard();
DoubleAnimation animation = new DoubleAnimation();
animation.To = newHeight;
animation.Duration = TimeSpan.FromSeconds(0.5);
Storyboard.SetTarget(animation, grid);
Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.HeightProperty));
story.Children.Add(animation);
story.Begin();
}
private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Grid grid = sender as Grid; //select the grid we tapped
AnimateHeight(grid);
}
請注意,我的推杆CacheMode參數來bitmapcache所有的網格。這不是必需的,但是會提供更流暢的動畫,因爲靜態網格不會在每個幀中重新繪製。
我試圖實現你的想法,唯一的問題是,我的行之一有一個rowspan兩個。第一行代替第二行,似乎第一行和第二行是一行,爲什麼? – JonasN89