我需要将一些参数或参数传递给 Page 的构造函数,看来我找不到办法。
这只是打开页面。如何将参数传递给 Page1 的构造函数? this.Frame.Navigate(typeof(Page1));
我需要将一些参数或参数传递给 Page 的构造函数,看来我找不到办法。
这只是打开页面。如何将参数传递给 Page1 的构造函数? this.Frame.Navigate(typeof(Page1));
As utterly strange as your question is, here's your answer. This is not a XAML question. This is simply a C# question. Creating a custom constructor on Page3 would be a simple as this:
public sealed partial class Page2 : Page
{
public Page2()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var p3 = new Page3(e.Parameter);
// do something
base.OnNavigatedTo(e);
}
}
public sealed partial class Page3 : Page
{
public Page3(object parameter)
: base()
{
this.NavigationCacheMode = NavigationCacheMode.Required;
this.InitializeComponent();
}
}
Please note two things:
Good luck.
You have to override OnNavigatedTo handler event and get parameters from it. Read something about NavigationService, eg. http://developer.nokia.com/Community/Wiki/Passing_parameters_while_navigating_between_pages_on_Windows_Phone
通常您应该将 MVVM 用于 XAML 应用程序。在这种情况下,您应该将值设置为 ViewModel 并将其设置为您的页面的上下文。