這將爲你做。
<Frame x:Name="Frm" Width="499" Height="248" Content="Frame" Navigating="Frame_Navigating_1" BorderThickness="2" BorderBrush="#FF21BD9A">
<Frame.RenderTransform>
<TranslateTransform x:Name="TransTrfm" />
</Frame.RenderTransform>
<Frame.Resources>
<Storyboard x:Key="SbKey">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
<LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
</DoubleAnimationUsingKeyFrames.KeyFrames>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0.15" Storyboard.TargetProperty="X" Storyboard.TargetName="TransTrfm">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0.0" />
<LinearDoubleKeyFrame KeyTime="0:0:0.17" Value="-1000.0" />
<LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.0" />
</DoubleAnimationUsingKeyFrames.KeyFrames>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0.35" Storyboard.TargetProperty="Opacity">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
</DoubleAnimationUsingKeyFrames.KeyFrames>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Frame.Resources>
</Frame>
代碼:
Storyboard sb;
private void Frame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (sb != null)
{
sb.Begin();
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
sb = (Storyboard)Frm.Resources["SbKey"];
Storyboard.SetTargetName(sb, "Frm");
Frm.Navigate("Page1.xaml");
}
您也可以嘗試使用ControlStoryboardAction
行爲,並ChangePropertyAction
行爲,避免代碼隱藏。
看這裏:http://www.codeproject.com/Articles/364529/Animation-using-Storyboards-in-WPF – Fruchtzwerg
在我看來,一個明顯的選擇是你的按鈕開始動畫而不是導航,並且根據動畫的狀態觸發導航。但這是一個非常模糊的輪廓;不可能確切知道你的情況下最適合哪種方式。沒有一個好的[mcve]顯示你已經嘗試過的,這個問題太廣泛了,不能在這裏合理地回答。 –