Silverlight 椭圆高度变换
我正在学习 Silverlight for WP7 并遇到一个小问题: 我想将高度转换为 1,然后围绕中心转换回来(这样看起来就像旋转)(它会自动执行宽度转换)。 代码:
<StackPanel x:Name="ContentPanel" Grid.Row="2" VerticalAlignment="Bottom">
<StackPanel.Resources>
<Storyboard x:Name="UpDownStoryBoard">
<DoubleAnimation Storyboard.TargetName="FirstEllipse"
Storyboard.TargetProperty="Height"
To="1" AutoReverse="True"
Duration="00:00:02" />
</Storyboard>
<Storyboard x:Name="LeftRightStoryBoard">
<DoubleAnimation Storyboard.TargetName="FirstEllipse"
Storyboard.TargetProperty="Width"
To="1" AutoReverse="True"
Duration="00:00:02" />
</Storyboard>
</StackPanel.Resources>
<Border VerticalAlignment="Top">
<Ellipse x:Name="FirstEllipse" Fill="Aqua" Height="150" Width="300" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Grid x:Name="ContentGrid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="438">
<Grid.RowDefinitions>
<RowDefinition Height="33*" />
<RowDefinition Height="33*" />
<RowDefinition Height="33*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
</Grid.ColumnDefinitions>
<Button Content="<" Height="80" HorizontalAlignment="Center" Name="_lButton" VerticalAlignment="Center" Width="80" Grid.Row="1" Click="StartLeftRightStoryBoard" />
<Button Content=">" Height="80" HorizontalAlignment="Center" Name="_rButton" VerticalAlignment="Center" Width="80" Grid.Column="2" Grid.Row="1" Click="StartLeftRightStoryBoard" />
<Button Content="^" Height="80" HorizontalAlignment="Center" VerticalAlignment="Center" Name="_uButton" Width="80" Grid.Column="1" Click="StartUpDownStoryBoard" />
<Button Content="v" Height="80" HorizontalAlignment="Center" VerticalAlignment="Center" Name="_dButton" Width="80" Grid.Column="1" Grid.Row="2" Click="StartUpDownStoryBoard" />
</Grid>
</StackPanel>
I'm learning Silverlight for WP7 and have come across a slight problem:
I want to transform the height to 1 and back (so it looks like spinning) around the center (it does it automatically for width).
Code:
<StackPanel x:Name="ContentPanel" Grid.Row="2" VerticalAlignment="Bottom">
<StackPanel.Resources>
<Storyboard x:Name="UpDownStoryBoard">
<DoubleAnimation Storyboard.TargetName="FirstEllipse"
Storyboard.TargetProperty="Height"
To="1" AutoReverse="True"
Duration="00:00:02" />
</Storyboard>
<Storyboard x:Name="LeftRightStoryBoard">
<DoubleAnimation Storyboard.TargetName="FirstEllipse"
Storyboard.TargetProperty="Width"
To="1" AutoReverse="True"
Duration="00:00:02" />
</Storyboard>
</StackPanel.Resources>
<Border VerticalAlignment="Top">
<Ellipse x:Name="FirstEllipse" Fill="Aqua" Height="150" Width="300" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Grid x:Name="ContentGrid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="438">
<Grid.RowDefinitions>
<RowDefinition Height="33*" />
<RowDefinition Height="33*" />
<RowDefinition Height="33*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
</Grid.ColumnDefinitions>
<Button Content="<" Height="80" HorizontalAlignment="Center" Name="_lButton" VerticalAlignment="Center" Width="80" Grid.Row="1" Click="StartLeftRightStoryBoard" />
<Button Content=">" Height="80" HorizontalAlignment="Center" Name="_rButton" VerticalAlignment="Center" Width="80" Grid.Column="2" Grid.Row="1" Click="StartLeftRightStoryBoard" />
<Button Content="^" Height="80" HorizontalAlignment="Center" VerticalAlignment="Center" Name="_uButton" Width="80" Grid.Column="1" Click="StartUpDownStoryBoard" />
<Button Content="v" Height="80" HorizontalAlignment="Center" VerticalAlignment="Center" Name="_dButton" Width="80" Grid.Column="1" Grid.Row="2" Click="StartUpDownStoryBoard" />
</Grid>
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是因为容器---Border元素。
Border位于StackPanel中,其高度由子元素决定。
因此,当椭圆的高度降低时,边框的高度也会降低。
解决办法很简单,给Border一个固定的Height。
例如
希望这有帮助。
It's because of the container --- Border element.
The Border is in a StackPanel, and its Height is decided by the child element.
So when the ellipse's height goes down, the Height of the Border goes down too.
Solution is simple, give the Border a fixed Height.
e.g.
Hope this helps.
也许这就是你想要的。
Maybe this is what you want.