I have a Button
defined in XAML that contains a Command
including a CommandParameter
. The Command
binds to the current view's ViewModel, while the CommandParameter
binds to another control within the current view. In WPF this would look like:
<TextBox x:Name="MyTextBox" />
<Button Command="{Binding ViewmodelCommand}"
CommandParameter="{Binding ElementName=MyTextBox, Path=Text}" />
According to documentation, in Xamarin.Forms View-to-View binding is possible via changing a control's BindingContext
using the x:Reference
markup extension:
<Button BindingContext="{x:Reference Name=MyTextBox}"
CommandParameter="{Binding Path=Text}" />
In this case, however, I'm not able to bind the Command
to the global Viewmodel! Are there any solutions to this scenario?
Did you solve this?
what I did was to add a binding MyTextBox <-> viewModel like:
MyTextBox.SetBinding(Entry.TextProperty, "PropName");
btn.SetBinding(Button.CommandProperty, "CommandName"); btn.SetBinding(Button.CommandParameterProperty, "PropName");