动画时网格列更改宽度 [英] Grid Column changing Width when animating
问题描述
我有一个 Grid 元素,它有两列和三行.最后一行的高度为 0...我使用自定义动画类为 height 属性设置动画,因为 gridheight 属性不是整数..
I have a Grid element that has two columns and three rows. The last row has a height of 0... and I animate the height property using a custom animation class because the gridheight property isnt an integer..
动画效果很好,但是当我激活它时,它似乎随机地改变了第二列的宽度.有时只是大几个像素,有时是宽度的两倍……
The animation works just fine, but when I activate it, it changes the width of the second column seemingly randomly.. sometimes just a few pixels bigger and sometimes over double as wide...
这里是网格代码
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="7"/>
<RowDefinition Name="LyricsRow" Height="1">
<RowDefinition.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsTrayOpen}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<local:GridLengthAnimation
Storyboard.TargetProperty="Height"
From="0" To="150" Duration="0:0:0.3" >
</local:GridLengthAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<local:GridLengthAnimation
Storyboard.TargetProperty="Height"
From="150" To="0" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
</Grid.RowDefinitions>
这有什么原因吗?
推荐答案
可能取决于单元格"的内容
It probably depends on the content of the "cells"
除了 Width="50" 之外,尝试在 columnDefinition 上设置 MaxWidth="50"
try setting MaxWidth="50" on your columnDefinition in addition to Width="50"
这篇关于动画时网格列更改宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!