How to transfer the parameter in the button and get the value in the code behind to redirect to another page depending on the parameter value in the Windows 7 phone?

I think if the Windows Phone 7 event is similar to ASP.NET development with C #, something like a button, I set the value for the command parameter in XAML, and in the code behind I get the command parameter and the page redirection.

I did not find any good examples for handling button events, any suggestions?

Thanks.

+4
source share
2 answers

For xaml:

<Button Tag="pageAddress" Click="Button_Click" /> 

And then by code:

 private void Button_Click(object sender, RoutedEventArgs e) { Button _button = (Button)sender; NavigationService.Navigate(new System.Uri(_button.Tag.ToString())); } 
+11
source

I would recommend you use the command parameter as you mentioned. So in your xaml do something like this:

 <Button x:name="myButton" CommandParameter="{Binding Title}" Click="myButton_Click"/> 

And in C # code something like this:

 private void myButton_Click(object sender, RoutedEventArgs e) { Button _myButton = (Button)sender; string value = _myButton.CommandParameter.ToString(); } 

Indeed, this is very similar to Teemu's answer, although I must admit that I have not used the Tag element before. According to the documentation on MSDN, the tag element should work very nicely, since it can store user information that you can access in your code (or viewmodel).

+7
source

Source: https://habr.com/ru/post/1391337/


All Articles