0

I have a user control which is shared between a lot of .xaml files which are user controls themselves. In the shared user control I have this code:

<controls:MyButton x:Name="Back" Tag="/Resources/Back.png" Content="Back" Command="{Binding Path=NavigateToPrevious}"/>

where MyButton is a button.

And the code works fine, it redirects me to the previous page on which I've been.

However, there are pages in my application which take a parameter in order to be shown. For example, I'm on page People, I go to John, click Back (Page is opened), click Back again (John shoul be opened). The People page lists all the people in my database, it doesn't need input parameters. But the Person page needs to know if I want John or Jack to be shown. Plus, it isn't just the Person page which needs input parametters.

How can I send that parametar via MyButton? MyButton is in a shared user control. The needed parameter is in a view model.

petko_stankoski
  • 10,459
  • 41
  • 127
  • 231

2 Answers2

1

I do not think that this is something which should be handled by the button itself, you should keep track of navigation, storing a stack of view model instances, each time back is clicked popping one and showing it in the view. The complete state (including the parameter) should be encapsulated in the instances on your stack.

(Also i do not think that hitting 'back' twice on a user page should land you on the same page, instead you should hit 'back' then 'forward' to achieve that, so your history should keep two stacks to navigate between)

H.B.
  • 166,899
  • 29
  • 327
  • 400
1

If sending parameter to command will solve your problem, then try to use CommandParameter. This will send the parameters to the command. Have a look at the answer, it explains how to use CommandParameter; this might help.

Community
  • 1
  • 1
Debasis
  • 408
  • 1
  • 3
  • 12