导航困难,因为框架不适合 [英] Navigation difficulties as frame not suitable

查看:101
本文介绍了导航困难,因为框架不适合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我目前遇到的问题超出了我的范围,希望得到一些帮助或指导.

我有一个包含UserControl的MainWindow.该UserControl的行为与Frame相似,但是UserControl包含一个ContentControl.框架不能具有直接的内容,因此我不得不使用UserControl. ContentControl处理UserControl内容更改时的动画.

Hi all,

I''ve got a problem that is a little beyond me currently and would appreciate some help or direction.

I have a MainWindow that contains a UserControl. This UserControl acts much as a Frame would, however the UserControl contains a ContentControl. Frames cannot have direct content so I had to use a UserControl. The ContentControl handles the animations for when the content of the UserControl changes.

uc:pagetransition x:name="pageHolder" transitiontype="Slide" panel.zindex="-1" />



我正在寻找一种利用导航框架的方法,以便在上述UserControl的内容发生更改时,会更新日志.我只能看到使用Frame或NavWindow的方法.我确实成功使用了Frame,直到需要一些平滑的动画效果为止.

如何连接我的应用程序以使用导航功能?

这是PageTransition UserControl背后的代码,该代码显示了它自己的ShowPage方法:



I''m looking for a way to utilise the Navigation Framework so that when the content of the above UserControl changes, a Journal is updated. I can only see ways to do this if I were to use a Frame or NavWindow. I did use a Frame successfully until some slicker animation effects were required.

How can I wire up my app to use the Navigation functionality?

Here is the code behind the PageTransition UserControl that shows it''s own ShowPage method:

public partial class PageTransition : UserControl
{
        Stack<usercontrol> pages = new Stack<usercontrol>();

        public UserControl CurrentPage { get; set; }

	public static readonly DependencyProperty TransitionTypeProperty = DependencyProperty.Register("TransitionType",
			typeof(PageTransitionType),
			typeof(PageTransition), new PropertyMetadata(PageTransitionType.SlideAndFade));

		public PageTransitionType TransitionType
		{
			get
			{
				return (PageTransitionType)GetValue(TransitionTypeProperty);
			}
			set 
			{
				SetValue(TransitionTypeProperty, value);
			}
		}

		public PageTransition()
		{
			InitializeComponent();

            nav = NavigationService.GetNavigationService(this);
		}		
		
		public void ShowPage(UserControl newPage)
		{			
			pages.Push(newPage);

			Task.Factory.StartNew(() => ShowNewPage());
		}


		void ShowNewPage()
		{
			Dispatcher.Invoke((Action)delegate 
				{
					if (contentPresenter.Content != null)
					{
						UserControl oldPage = contentPresenter.Content as UserControl;

						if (oldPage != null)
						{
							oldPage.Loaded -= newPage_Loaded;

							UnloadPage(oldPage);
						}
					}
					else
					{
						ShowNextPage();
					}
					
				});
		}

		void ShowNextPage()
		{
			UserControl newPage = pages.Pop();

			newPage.Loaded += newPage_Loaded;

			contentPresenter.Content = newPage;
		}

		void UnloadPage(UserControl page)
		{
			Storyboard hidePage = (Resources[string.Format("{0}Out", TransitionType.ToString())] as Storyboard).Clone();

			hidePage.Completed += hidePage_Completed;

			hidePage.Begin(contentPresenter);
		}

		void newPage_Loaded(object sender, RoutedEventArgs e)
		{
			Storyboard showNewPage = Resources[string.Format("{0}In", TransitionType.ToString())] as Storyboard;

			showNewPage.Begin(contentPresenter);

			CurrentPage = sender as UserControl;
		}		

		void hidePage_Completed(object sender, EventArgs e)
		{
			contentPresenter.Content = null;

			ShowNextPage();
		}

	}
</usercontrol></usercontrol>




问候,

Jib




Regards,

Jib

推荐答案

好吧,由于我无法利用日记本,因此我实现了自己的导航处理方法.尚不完全正确,但希望在完成后将其发布.
Well I''ve implemented my own method of Navigation handling as I couldn''t utilise the Journal. It''s not exactly right yet, but I''ll post it when finished hopefully.


这篇关于导航困难,因为框架不适合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆