[英]WPF Frame triggers via storyboard
I am quite new to C#/WPF in general, so it is quite possible I am missing something. 一般来说,我对C#/ WPF还是很陌生,所以很可能会丢失一些东西。
Is there a way to animate a Frame
via a storyboard that will trigger on the Frame.Navigating
event ? 有没有一种方法可以通过会在
Frame.Navigating
事件上触发的情节Frame.Navigating
来对Frame
进行动画Frame.Navigating
? Most of the common ones I can choose from such as Frame.Loaded
not the event I am after however. 我可以从中选择大多数常见的东西,例如
Frame.Loaded
而不是我Frame.Loaded
的事件。
edit: I wonder is a Custom RoutedEvent the best way to approach this? 编辑:我想知道自定义RoutedEvent是解决此问题的最佳方法吗?
When a user clicks a button the Frame.Navigate
method is called and loads in a new Page. 当用户单击按钮时,将
Frame.Navigate
方法并加载到新的Page中。
What I would like to happen is... 我想发生的是...
This will do it for you. 这将为你做到。
<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>
Code : 代码:
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");
}
You can also try using ControlStoryboardAction
behavior, and ChangePropertyAction
behavior to avoid code-behind. 您也可以尝试使用
ControlStoryboardAction
行为和ChangePropertyAction
行为来避免代码隐藏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.