【发布时间】:2016-05-16 13:11:23
【问题描述】:
我在不同视图之间共享简单变量时遇到了一些问题。
我有第一个名为 MainPage.xaml 的主视图,第二个名为 Page2.xaml。
我想检查 MainPage.xaml 上的哪个单选按钮被选中,并将带有该日期的变量发送到 Page2.xaml。
主页:
namespace IDG
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public string choice;
public MainPage()
{
this.InitializeComponent();
}
private void bt_start_Click(object sender, RoutedEventArgs e)
{
if (rb_choice1.IsChecked == true)
{
choice = "choice1";
}
if (rb_quiz.IsChecked == true)
{
this.Frame.Navigate(typeof(Page2), choice);
}
}
}
}
第 2 页:
namespace IDG
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Page2 : Page
{
private string x;
public Page2()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var param = e.Parameter as string;
x = param;
textBlock1.Text = x;
}
private void button_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MainPage));
}
}
}
而我希望这个参数存放在主类中,怎么做呢?
【问题讨论】:
标签: c# xaml win-universal-app views