<Button x:Name="ButtonLogin"
StyleId="ButtonLogin"
Grid.Row="5"
BackgroundColor="#F44336"
BorderRadius="0"
TextColor="White"
Text="Login to Meetup"
Command="{Binding LoginCommand}" />
or
<Button x:Name="ButtonLogin"
StyleId="ButtonLogin"
Grid.Row="5"
BackgroundColor="#F44336"
BorderRadius="0"
TextColor="White"
Text="Login to Meetup"
Clicked="LogMeIn" />
Does the use of one or the other matter specifically when designing a Xamarin
app?
Which approach should be used?
Regardless of whether it is WPF XAML
, Silverlight XAML
or Xamarin XAML
, the choice to use one or the other does not affect the end performance of the app for at some point it all gets distilled down to codebehind and ultimately into machine code.
With that said if one uses commanding it can be designed to work within the MVVM
paradigm and give direct access to functionality which can be either based on the View
, ViewModel
and even the Model
depending on how it is set up.
Since a command is based on ICommand interface, that gives the XAML more flexibility to either allow or disallow operations due to the CanExecute
functionality which is a big selling point if used.
Both can be used in Xamarin xaml template[?]
The click event is local to the control and cannot be used in a template. The click event can work with MVVM
but it should not be called from anywhere outside the View
that contains it.
My advice is to use Commanding
where re-use particulary amongst Pages
/Views
is prevalent and also if there exists a need to either directly or indirectly affect styles and visibility; use it. Otherwise if the operation is just local to the page/control there is no reason not to use code-behind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With