我試圖創建一個簡單的動畫,其中網格從0高度動畫到320的設置值(這將給出滑動感覺),同時也動畫從0-1開始不透明並返回。動畫網格的高度在Windows Phone 8.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;
的問題是在高度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>
正如我所說,爲什麼動畫沒有做到高度?
忘了提及我已經嘗試過使用From值,但沒有什麼區別。 – Tokfrans 2014-10-04 21:00:58
好吧,你有沒有嘗試過使用'(FrameworkElement。高度)「而不是」高度「。我會編輯我的答案,告訴你 – RedLaser 2014-10-04 22:44:04