简体   繁体   English

在Windows Phone 8页面之间传递按钮名称

[英]Passing Button name between pages windows phone 8

I need a little help passing a button name/value to another page. 我需要一些帮助,将按钮名称/值传递给另一个页面。 Example Page one has a button with name "Button 1". 示例第一页有一个名为“按钮1”的按钮。 Page two has a public string called "Passed-button-name". 第二页有一个公共字符串,称为“ Passed-button-name”。 When a user press a button one in page one, The string value in page will be same as the button name. 当用户按下第一页中的一个按钮时,页面中的字符串值将与按钮名相同。 How will i go about creating this?? 我将如何创建这个? thanks in advance 提前致谢

You can use query string parameter for string variable like below : 您可以对字符串变量使用查询字符串参数,如下所示:

NavigationService.Navigate(new Uri("/SecondPage.xaml?key=value", Urikind.Relative)); NavigationService.Navigate(new Uri(“ / SecondPage.xaml?key = value”,Urikind.Relative));

To get it on the target page: 要在目标页面上获取它:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    if (NavigationContext.QueryString.ContainsKey("key"))
    {
         string val = NavigationContext.QueryString["key"];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM