【发布时间】:2014-10-04 13:30:51
【问题描述】:
我正在尝试创建一个简单的动画,其中网格从 0 高度动画到设定值 320。(这将产生滑动感觉),同时还动画从 0-1 和返回的不透明度。
我创建了两个故事板并给它们起了名字,它们是:
<Page.Resources>
<Storyboard x:Name="OpenSettings" Storyboard.TargetName="SettingGrid">
<DoubleAnimation Storyboard.TargetProperty="Height" Storyboard.TargetName="SettingGrid" To="320"/>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SettingGrid" To="1"/>
</Storyboard>
<Storyboard x:Name="CloseSettings">
<DoubleAnimation Storyboard.TargetProperty="Height" Storyboard.TargetName="SettingGrid" To="0"/>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SettingGrid" To="0"/>
</Storyboard>
</Page.Resources>
我尝试从代码隐藏运行动画,如下所示:
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
if (settingsOpened)
{
CloseSettings.Begin();
settingsOpened = false;
}
else
{
OpenSettings.Begin();
settingsOpened = true;
}
}
bool settingsOpened = false;
问题在于Height-doubleanimation。它不会改变网格上的任何高度值。顺便说一下,不透明度动画效果很好。
有谁知道我可以如何解决这个问题?
这也是我要制作动画的网格。请注意我是如何设置固定的起始值的,这使得动画中的“from”属性变得不必要。
<Grid Opacity="1" Height="0" VerticalAlignment="Top" Name="SettingGrid" Background="#151515">
<CheckBox Margin="10,0,0,0" Content="Use front camera" Height="80"/>
<TextBlock Text="IP Address" Margin="10,70,10,0" FontSize="25" FontWeight="Light" Height="30" VerticalAlignment="Top"/>
<TextBox Text="127.0.0.1" Margin="10,100,10,0" Height="40" VerticalAlignment="Top" Name="IPBox"/>
<TextBlock Text="Port" Margin="10,150,10,0" FontSize="25" FontWeight="Light" Height="30" VerticalAlignment="Top"/>
<TextBox Text="12345" Margin="10,180,10,0" Height="40" VerticalAlignment="Top" Name="PortBox"/>
<Slider Margin="10,230,10,0" Height="45" VerticalAlignment="Top" Name="updateFreq" Value="20"/>
<StackPanel Margin="10,270,0,0" Orientation="Horizontal">
<TextBlock FontSize="25" VerticalAlignment="Top" Margin="10,0,0,0" FontWeight="Light" HorizontalAlignment="Left" Text="{Binding ElementName=updateFreq, Path=Value}"/>
<TextBlock Text=" Times per second" FontSize="25" FontWeight="Light" VerticalAlignment="Top"/>
</StackPanel>
</Grid>
正如我所说,为什么动画没有对高度做任何事情?
【问题讨论】:
标签: c# wpf xaml windows-phone-8.1