网格列在动画时改变宽度
我有一个具有两列和三行的网格元素。最后一行的高度为 0...我使用自定义动画类对 height 属性进行动画处理,因为 gridheight 属性不是整数。
动画效果很好,但是当我激活它时,它会更改第二个的宽度列看起来是随机的..有时只是大几个像素,有时宽度超过两倍...
这是网格代码
<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>
是否有任何原因可能会发生这种情况?
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...
Here is the grid code
<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>
Is there any reasons this could be going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些可能想知道问题中提到的 GridLengthAnimation 实现的人,这里有一个(来自 http://social.msdn.microsoft.com/forums/en-US/wpf/thread/da47a4b8-4d39-4d6e-a570-7dbe51a842e4/)
For those of you that might be wondering about the GridLengthAnimation implementation mentioned in the question, here is one (from http://social.msdn.microsoft.com/forums/en-US/wpf/thread/da47a4b8-4d39-4d6e-a570-7dbe51a842e4/)
这可能取决于“单元格”的内容,
除了 Width="50" 之外,还尝试在您的 columnDefinition 上设置 MaxWidth="50"
It probably depends on the content of the "cells"
try setting MaxWidth="50" on your columnDefinition in addition to Width="50"