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));
}
}

浙公网安备 33010602011771号