I'm developing an Android application using Xamarin and MvvmCross. As seen in the layout posted at the bottom of this question I have a TextView
and a Button
.
I want to achieve the following things:
Bind the OnClick listener of the button to the
onClikCommand
method as shown in the code below.When the
onClikCommand
is called I expect the value of the Text attribute of theTextView
to change according to the evaluation of the if-statement.Broadcast the value of the evaluation via a cutomized EventHandler and EventArgs.
Concerning the binding part, I've read several tutorials and I found that some developers are using
ICommand interface and Command in the property of UI-Command,
and some are using
local:Mvx
My question is, what is the difference between both kinds of bindings and in which context either of them is preferred?
code_VM : IMvxNotifyPropertyChanging
public event EventHandler<ValidPlayValueEventArgs> ValidPlayValueEventHandler;
public ICommand onClikCommand {get; private set;}
public isValidPlayValue {get; private set;}
public VM() {
onClikCommand = new Command<string, string, string>(isValidPlay);
}
public class ValidPlayValueEventArgs : EventArgs {
public isValidPlay {get; private set;}
public ValidPlayValueEventArgs(bool isValid) {
isValidPlay = isValid;
}
}
public void isValidPlay(string p1, string p2, string p3) {
if (p1 && p2 && P3) {
isValidPlayValue = true;//<----I expect this to update/set value in the textview!! true??
ValidPlayValueEventHandler(this, new ValidPlayValueEventArgs(true));
} else {
isValidPlayValue = false;//<----I expect this to update/set value in the textview!! true??
ValidPlayValueEventHandler(this, new ValidPlayValueEventArgs(false));
}
}
Layout
<TextView
Command="{Binding isValidPlayValue}"
<Button
Command="{Binding onClikCommand}"