I am developing a simple Xamarin.Forms app using a MVVM approach with VS 2017. Everything works as expected in UWP but my Android project does not execute the lines of code that get/set ICommand properties at all. I can set a breakpoint on the line that sets the property value, as well as the line before and the line after. I break on both lines before and after, but not on the line that sets the property.
Here is my view model code:
public LoginPageViewModel(INavigation navigation) : base()
{
Navigation = navigation;
LoginButtonClicked = new Command(Login, () => true);
PasswordHintButtonClicked = new Command(PasswordHint, () => true);
}
And my XAML.cs:
btnLogin.SetBinding(Button.CommandProperty, nameof(vm.LoginButtonClicked), BindingMode.OneWay);
btnPasswordHint.SetBinding(Button.CommandProperty, nameof(vm.PasswordHintButtonClicked), BindingMode.OneWay);
As I said, I can break on setting the Navigation property but not the command properties. If I move Navigation = navigation
to the last line of the constructor I still break on it.
I've also tried:
private ICommand _loginButtonClicked; public ICommand LoginButtonClicked { get { return _loginButtonClicked ?? (_loginButtonClicked = new Command(Login, () => true)); } }
This should be pretty straightforward. Maybe I made a mistake configuring the Android emulator? I've been beating my head against this for a few days now, if anyone has seen something like this before I'd appreciate a nudge in the right direction.
Thanks!