[英]C# and XAML pass button Click String to another page textblock
我正在尝试将字符串传递给另一个xaml页面中的文本块
我有一个页面(Gender.xaml),其中有两个按钮(男性和女性),当用户单击按钮时,它将打开另一问题页面。
我正在尝试在question.xaml页面顶部的标签TextBlock中显示用户选择的按钮的性别。
代码中的任何一个是否要在另一个Questions.xaml页面中传递/显示字符串值
这是我到目前为止在Gender.xaml页面中所拥有的
private void MaleButton_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Questions.xaml", UriKind.Relative));
GenderLabel.Text = string.Format("Male");
}
private void FemaleButton_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Questions.xaml", UriKind.Relative));
GenderLabel.Text = string.Format("Female");
}
任何帮助或建议,不胜感激
工作方式如下
string gender = "Male"; // or "Female";
NavigationService.Navigate(new Uri("/Questions.xaml?gender=" + gender, UriKind.Relative));
在Questions.xaml.cs上,您具有:
override void OnNavigatedTo(NavigationEventArgs e)
{
string gender = e.Uri.OriginalString.Replace("/Questions.xaml?gender=","");
//you do what you want with gender;
}
像这样导航:
this.Frame.Navigate(typeof(Questions),"female");
并在导航页面上
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string gender = e.Parameter.ToString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.