Pass Data to Pages when Navigating in a WPF Navigation Application

The method that was marked off is less efficient because of box-unbox

But the current method is kind of an one-way communication approach,while the less efficient method is a multi-way communication one, so….

public partial class Page2 : System.Windows.Controls.Page
    {
        public Page2(string myName)
        {
            InitializeComponent();
            txtPassname.Text = myName;

        }

        //protected override void OnInitialized(EventArgs e)
        //{
        //    base.OnInitialized(e);
        //    txtPassname.Text = Application.Current.Properties["myname"].ToString();
        //}
    }

 

public partial class Page1 : System.Windows.Controls.Page
    {
        public Page1()
        {
            InitializeComponent();
        }

        void Button_Click(object sender, RoutedEventArgs e)
        {
            //Application.Current.Properties["myname"] = txtName.Text;
            this.NavigationService.Navigate(new Page2(txtName.Text));
        }

    }

posted @ 2009-11-26 14:34  pursue  阅读(77)  评论(0)    收藏  举报