2
votes

I have an Entry and a Button. I want the command "CallWebServiceCommand" to be called when I press the button. The call to that command needs to include the url of the web service as a CommandParameter. The BindingContext is set to the ViewModel of the page.

The CommandParameter property of the button needs to reference the Text property of the entry. In WPF, I could do something like this:

<Button Text="Call web service" Command="{Binding CallWebServiceCommand}" CommandParameter="{Binding ElementName=url, Path=Text}" />

I know that it's not possible to have multiple binding contexts per view, but what would be a good workaround for this particular situation?

1

1 Answers

2
votes

This is a bit of a hack, but it's worked for us in the past: Use the ViewModel as a "relay" for the view. To do this, create a String property on your ViewModel that the text field binds its Text property to, and bind the CommandParameter of the button to this property. If you raise the PropertyChanged event for this "parameter" property, the command will supply the updated value to the method specified as the command's Action. It's certainly non-ideal, but it does work as a poor man's replacement for RelativeSource binding.