![](/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.