怎么用WPF中的Frame控件做过渡效果? [英] How do you do transition effects using the Frame control in WPF?
问题描述
我认为这很容易,但我想不会.
I thought this would be easy but I guess not.
我有 2 个页面加载到我的框架控件中.我希望能够拥有从一页到下一页的漂亮幻灯片效果或只是简单的淡入效果.
I have 2 pages that load in my frame control. I want to be able to either have a nice slide effect from one page to the next or just a simple fade-In effect.
似乎在互联网上的任何地方都找不到.
Can't seem to find this anywhere on the internets.
更新 1接受的答案很好,但我在这里找到了更好的答案.http://www.japf.fr/2008/07/8/评论页面 1/
Update 1 The accepted answer is good, but I found an even better one here. http://www.japf.fr/2008/07/8/comment-page-1/
更新 2如果你能相信,我找到了一个更好的解决方案.
http://fluidkit.codeplex.com/
Update 2
If you can believe it I found an even better solution.
http://fluidkit.codeplex.com/
推荐答案
这里讨论了一个类似的问题:导航到页面时的过渡淡入淡出动画 使用那里描述的技术,您可以在每次导航新页面时滑动移动框架控件.像这样:
There is a similar problem discussed here: Transition Fade Animation When Navigating To Page Using the technique described there you can slidemove your frame control each time a new page is navigated. Smth like this:
xml:
...
<Frame Name = "frame" Navigating="frame_Navigating">
...
代码:
...
private bool _allowDirectNavigation = false;
private NavigatingCancelEventArgs _navArgs = null;
private Duration _duration = new Duration(TimeSpan.FromSeconds(1));
private double _oldHeight = 0;
private void frame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (Content!=null && !_allowDirectNavigation)
{
e.Cancel = true;
_navArgs = e;
_oldHeight = frame.ActualHeight;
DoubleAnimation animation0 = new DoubleAnimation();
animation0.From = frame.ActualHeight;
animation0.To = 0;
animation0.Duration = _duration;
animation0.Completed += SlideCompleted;
frame.BeginAnimation(HeightProperty, animation0);
}
_allowDirectNavigation = false;
}
private void SlideCompleted(object sender, EventArgs e)
{
_allowDirectNavigation = true;
switch (_navArgs.NavigationMode)
{
case NavigationMode.New:
if (_navArgs.Uri == null)
frame.Navigate(_navArgs.Content);
else
frame.Navigate(_navArgs.Uri);
break;
case NavigationMode.Back:
frame.GoBack();
break;
case NavigationMode.Forward:
frame.GoForward();
break;
case NavigationMode.Refresh:
frame.Refresh();
break;
}
Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
(ThreadStart)delegate()
{
DoubleAnimation animation0 = new DoubleAnimation();
animation0.From = 0;
animation0.To = _oldHeight;
animation0.Duration = _duration;
frame.BeginAnimation(HeightProperty, animation0);
});
}
...
希望能帮到你,问候
这篇关于怎么用WPF中的Frame控件做过渡效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!