我有一个用户需要来回导航的程序。基本上有{仪表板,设置......} 我使用用户控件实现它们,所以我有我的Window,以及加载它的用户控件。 我用它在他们之间导航的页面切换器代码(azerdark.wordpress.com/2010/04/23/multi-page-application-in-wpf)
我想要的是动画用户控件在我的窗口中加载时的导航方式。 我找到的最简单的方法是在我的窗口上创建一个Frame并为其设置动画..我做了,但是我无法提升触发动画的事件。我尝试在加载的窗口上进行动画制作以进行测试并且工作正常,但是当我的窗口中加载了用户控件时,动画无效。
这是我的代码 XAML:{PageSwitcher - 加载用户控件的我的窗口}
<Window.Resources>
<Storyboard x:Key="FadeLeft">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="myFrame">
<EasingDoubleKeyFrame KeyTime="0" Value="900">
<EasingDoubleKeyFrame.EasingFunction>
<ExponentialEase EasingMode="EaseOut" Exponent="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<ExponentialEase EasingMode="EaseOut" Exponent="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="myFrame">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Visible}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.6" Value="{x:Static Visibility.Hidden}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="myFrame">
<EasingDoubleKeyFrame KeyTime="0" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<PowerEase EasingMode="EaseOut" Power="2"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<PowerEase EasingMode="EaseOut" Power="2"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Frame x:Name="myFrame" Content="" Background="#FF8F4646" Visibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Disabled" RenderTransformOrigin="0.5,0.5">
<i:Interaction.Triggers>
<i:EventTrigger EventName="x:Static local:PageSwitcher.ainmate">
<ei:ControlStoryboardAction Storyboard="{StaticResource FadeLeft}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Frame.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Frame.RenderTransform>
</Frame>
XAML.cs
public static readonly RoutedEvent animate = EventManager.RegisterRoutedEvent(
"Fade", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(PageSwitcher));
public event RoutedEventHandler Fade
{
add { AddHandler(animate, value); }
remove { RemoveHandler(animate, value); }
}
public void RaiseAnimateEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(PageSwitcher.animate);
RaiseEvent(newEventArgs);
}
在调用Navigate以将用户控件的内容加载到我的窗口之前,我的Switcher类中会引发动画事件
XAML.cs {Switcher - 仅将我的窗口内容设置为调用Navigate时传递的用户控件。}
public static void Switch(UserControl newPage)
{
pageSwitcher.Navigate(newPage);
pageSwitcher.RaiseAnimateEvent();
}
我的代码有什么问题吗?为什么动画不起作用? 当我在UserControls
之间导航时,框架不显示感谢您的帮助