Don*_* V. 16 c# wpf user-interface frame
我觉得这很容易,但我猜不是.
我有两页加载到我的帧控件中.我希望能够从一个页面到下一个页面具有漂亮的幻灯片效果,或者只是一个简单的淡入效果.
似乎无法在互联网上的任何地方找到它.
更新1 接受的答案很好,但我在这里找到了更好的答案. http://www.japf.fr/2008/07/8/comment-page-1/
更新2
如果您相信它我找到了更好的解决方案.
http://fluidkit.codeplex.com/
ser*_*nko 19
此处讨论了类似的问题:导航到页面时的过渡淡化动画使用此处描述的技术,您可以在每次导航新页面时滑动\移动帧控件.像这样的Smth:
XAML:
...
<Frame Name = "frame" Navigating="frame_Navigating">
...
Run Code Online (Sandbox Code Playgroud)
码:
...
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);
});
}
...
Run Code Online (Sandbox Code Playgroud)
希望这有帮助,问候
我的答案是serge_gebunko给出的答案的改进版本.
它为您提供滑动左右效果.
XAML
...
<Frame Name = "MainFrame" Navigating="MainFrame_OnNavigating">
...
Run Code Online (Sandbox Code Playgroud)
C#
private void MainFrame_OnNavigating(object sender, NavigatingCancelEventArgs e) {
var ta = new ThicknessAnimation();
ta.Duration = TimeSpan.FromSeconds(0.3);
ta.DecelerationRatio = 0.7;
ta.To = new Thickness(0 , 0 , 0 , 0);
if (e.NavigationMode == NavigationMode.New) {
ta.From = new Thickness(500, 0, 0, 0);
}
else if (e.NavigationMode == NavigationMode.Back) {
ta.From = new Thickness(0 , 0 , 500 , 0);
}
(e.Content as Page).BeginAnimation(MarginProperty , ta);
}
Run Code Online (Sandbox Code Playgroud)