More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Friday, 27 July 2018 10:22:13 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

Xamarin forms clicked event versus Command Binding
Both Xamarin forms clicked event and Command Binding work fine without performance difference for all the following 8 classes.
Button
MenuItem
ToolbarItem
SearchBar
TextCell
ImageCell
ListView
TapGestureRecognizer

A clicked event defined in page view xaml: Clicked="button_Clicked"

code behind
Code:
           private void button_Clicked(object sender, EventArgs e)
           {

           }


The clicked event handler is a traditional approach. It is local to the control. It can an work with MVVM but it should not be called from anywhere outside the View that contains it.

However, with Command Binding, data bindings can make method calls directly to a ViewModel from the controls:

ClickedCommand="{Binding Path=BindingContext.MyCommand, Source={x:Reference MyPage}}" ClickedCommandParameter="{Binding .}"

Further more, Command Binding can be designed to work within the MVVM 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.

To implement Command Binding, a ViewModel defines one or more properties of type ICommand, which are then connected to the Command properties of UI controls through data binding. 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.

Regardless of whether it is Xamarin XAML for cross platform mobile app, WPF XAML for desktop or Silverlight XAML, it doesn't seem to have any difference in terms of performance as mentioned earlier.

If the operation is just local to the page or control, we can just simply use code-behind.
Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.