zoukankan      html  css  js  c++  java
  • silverlight学习之页面传值篇

    1、silverlight 实现页面导航跳转
       (1)利用根视图
        A、修改App.xmal.cs
         //使用根视图实现页面导航跳转
            //申明一个Grid对象
            private Grid rootGrid = new Grid();

            private void Application_Startup(object sender, StartupEventArgs e)
            {
                this.RootVisual = rootGrid;
                rootGrid.Children.Add(new MainPage());
            }

            //定义方法实现导航
            public static void Navigation(UserControl newPage)
            {
                //获取当前的Application实例
                App currentApp = (App)Application.Current;
                //修改当前显示的页面内容
                currentApp.rootGrid.Children.Clear();
                currentApp.rootGrid.Children.Add(newPage);
            }

         B、在页面MainPage.xaml中调用

         private void button1_Click(object sender, RoutedEventArgs e)
            {
                App.Navigation(new Control1());
            }


        这样,当我在点击button按钮时,就会从MainPage.xaml页面跳转到Control1.xaml页面了。


    2、silverlight中实现页面传值
       
       该实例中使用独立存储的IsolatedStorageSettings 对象进行页面之间的传值

        将文本框txtName的值由MainPage.xaml页面传到Main.xaml页面。

       (1)使用该对象前,要在cs页面调用命名空间:System.IO.IsolatedStorage;
       (2)MainPage.xaml:
         //定义独立的存储对象
            private IsolatedStorageSettings appSetting = IsolatedStorageSettings.ApplicationSettings;
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (txtName.Text != null && txtPwd.Text != null)
                {
                    if (txtName.Text == "rainie" && txtPwd.Text == "123")
                    {
                        //页面传值
                        if (!appSetting.Contains("name"))
                        {
                            appSetting.Add("name", txtName.Text.Trim());
                        }
                  else
                  {
                   appSetting.Clear();
                   appSetting.Add("name",txtName.Text.Trim());
                }

                        App.Navigation(new Main());
                    }
                }
            }

        (3)Main.xaml接收值:
         //申明变量
            private IsolatedStorageSettings appSetting = IsolatedStorageSettings.ApplicationSettings;
            private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
            {
                if (appSetting.Contains("name"))
                {
                    tbName.Text = appSetting["name"].ToString();
                }
            }

        
        这样就实现了silverlight的页面传值功能。

  • 相关阅读:
    我的浏览器收藏夹分类
    我的浏览器收藏夹分类
    Java实现 LeetCode 318 最大单词长度乘积
    Java实现 LeetCode 318 最大单词长度乘积
    Java实现 LeetCode 318 最大单词长度乘积
    Java实现 LeetCode 316 去除重复字母
    Java实现 LeetCode 316 去除重复字母
    Java实现 LeetCode 316 去除重复字母
    Java实现 LeetCode 315 计算右侧小于当前元素的个数
    Java实现 LeetCode 315 计算右侧小于当前元素的个数
  • 原文地址:https://www.cnblogs.com/qiernonstop/p/3735730.html
Copyright © 2011-2022 走看看