0

I have MainPaqe.cs (MainPaqe.xaml) and Periodic_Request.cs (Periodic_Request.xaml), in addition, Periodic_Request.xaml has TextBox with name TxtBlock_numRequest and Combobox with name CmbBox_lvlPriority with possible 3 options.

The problem is how get user written numbers or strings from TextBox and Combobox in the MainPaqe.cs. I need to get all this information after pressing button.

I completely can`t understand how to write it and use that pattern, so this why I need actual code

3 Answers 3

3

You can try passing the data in a QueryString? Check out this link for samples

private void button_Click(object sender, RoutedEventArgs e)
{
    string uri = String.Format("/Periodic_Request.xaml?numRequest={0}", TxtBlock_numRequest.Text);
    NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
2
  • Thank you a lot @miguelarcilla, I wasted hours to solve this problem
    – Rocketq
    Nov 18, 2013 at 14:09
  • 1
    @Rocketq No worries ;) GeekChamp is a really big help for a lot of those little questions. If you're doing MVVM, you could look at frameworks to make it easy on yourself. (mvvmlight.codeplex.com is a good example) Nov 19, 2013 at 0:49
1

What I usually do if I have just a few of this things that need to be passed to the main page is define them as static properties in the App.xaml.cs file

Then you can do something like this;

MainPage_OnNavigatedTo(object sender, Eventargs args)
{
    if(App.YourProperty != null)
    {
         _viewmodel.RefreshValueForFoo(App.YourProperty);
    }
}

It's not the nicest solution but it gets the job done when you have just a few values that need to be passed around

1

You could either send a querystring like miguel suggested, or have static properties, but both aren't too great. (why would I need to have a property everybody can see? or why would i have to create a querystring).

The solution when working with WPF usually lends itself in the use of the MVVM pattern, and in turn, using a messenger class to send a message. You can send whatever message you want, and whomever is supposed to listen to it, will receive it (once he register for that type of message).

I'm very happy with MVVM-Light implementation.

Here's a general example on how to use the messenger: http://jesseliberty.com/2011/01/06/windows-phone-from-scratch%E2%80%93mvvm-light-toolkit-soup-to-nuts-3/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.