silverlight实现页面跳转,保存上次的页面访问的状态,像手机应用一样

首先定义个主的xaml,把其中默认的grid删掉。

然后在App_start中,写入 new page1();

在page1的构造中把 this.content = ?,这里的?表示的是一个UserControl的集合。


最主要的是自己定一个类,用来存放按照 key值找到对应的UserContraol的对象信息,并保存程序启动时的page1对象。

这样在页面跳转时就可以获取到最初的这些个对象信息了。


namespace myTest
{

    public class PageDict
    {
        protected static UserControl rootPage;
        protected static Dictionary<string, UserControl> _pageDict = new Dictionary<string, UserControl>();
           
        public PageDict()
        {
        }

        public static void setRootPage(UserControl page)
        {
            rootPage = page;
        }

        public static UserControl getRootPage()
        {
            return rootPage;
        }
 

        public static UserControl popPage(string pageKey)
        {
            return (UserControl)(_pageDict[pageKey]);
        }

        public static Int16 pushPage(string key, UserControl userPage)
        {
            if (_pageDict.ContainsKey(key))
            {
                System.Windows.MessageBox.Show("Already has this key.");
                return -1;
            }

            _pageDict.Add(key, userPage);

            return 0;
        }
    }
}

在从一个页面跳转到另一个页面时:
        private void hylink1_Click(object sender, RoutedEventArgs e)
        {
            myPage1 newPage = new myPage1();

            PageDict.pushPage(Resource1.MainPageKey, this);

            PageDict.getRootPage().Content = newPage;
        }



        private void myBTN_Click(object sender, RoutedEventArgs e)
        {
            MainPage newPage = (MainPage)PageDict.popPage(Resource1.MainPageKey);

            if (newPage == null)
            {
                System.Windows.MessageBox.Show("we get a null page.");

                return;
            }
            

            PageDict.getRootPage().Content = newPage;

        }


 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值