![](/img/trans.png)
[英]How to extract Storyboard from Viewport3d.Triggers in wpf
[英]WPF Frame triggers via storyboard
一般來說,我對C#/ WPF還是很陌生,所以很可能會丟失一些東西。
有沒有一種方法可以通過會在Frame.Navigating
事件上觸發的情節Frame.Navigating
來對Frame
進行動畫Frame.Navigating
? 我可以從中選擇大多數常見的東西,例如Frame.Loaded
而不是我Frame.Loaded
的事件。
編輯:我想知道自定義RoutedEvent是解決此問題的最佳方法嗎?
當用戶單擊按鈕時,將Frame.Navigate
方法並加載到新的Page中。
我想發生的是...
這將為你做到。
<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
行為來避免代碼隱藏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.