-
Notifications
You must be signed in to change notification settings - Fork 4
Added SelectedItemChanged event #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Added SelectedItemChanged event
@@ -7,11 +7,12 @@ | |||
<ContentPage.BindingContext> | |||
<local:MainViewModel /> | |||
</ContentPage.BindingContext> | |||
<local:BindableStackLayout | |||
<local:BindableStackLayout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, it will make sense to add a sample of binding to SelectedItem
.
It will require to implement a INotifyPropertyChanged
on the VM level and add public property with getter and setter.
if (layout == null) | ||
return; | ||
|
||
foreach (var child in layout.Children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to add a TapGestureRecognizer
to sub views?
|
||
protected readonly ICommand ItemSelectedCommand; | ||
|
||
protected void AddGesture(View view, TapGestureRecognizer gesture) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why
protected
? In my opinion should beprivate
. - There are different types of Gestures, it will make sense to rename the method to
AddTapGestureRecognize
.
P.S.: In order to keep the code style consistent the access modifier private
should be removed as it is a default access modifier.
return view; | ||
} | ||
|
||
protected readonly ICommand ItemSelectedCommand; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why protected
? In my opinion should be private
and since it is a field it should be declared before constructor.
P.S.: In order to keep the code style consistent the access modifier private
should be removed as it is a default access modifier.
} | ||
} | ||
|
||
void PopulateHeader() => header.Text = Title; | ||
|
||
protected virtual View GetItemView(object item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why protected
and virtual
? In my opinion should be just private
.
P.S.: In order to keep the code style consistent the access modifier private
should be removed as it is a default access modifier.
itemsView.SetSelectedItem(newValue); | ||
} | ||
|
||
protected virtual void SetSelectedItem(object selectedItem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why protected
and virtual
? In my opinion should be just private
.
P.S.: In order to keep the code style consistent the access modifier private
should be removed as it is a default access modifier.
if (newValue == oldValue) | ||
return; | ||
|
||
itemsView.SetSelectedItem(newValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method SetSelectedItem(..)
can be replaced with a single line of code SelectedItemChanged?.Invoke(...)
propertyChanged: OnSelectedItemChanged | ||
); | ||
|
||
private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to keep the code style consistent the access modifier private
should be removed as it is a default access modifier.
returnType: typeof(object), | ||
declaringType: typeof(BindableStackLayout), | ||
defaultValue: null, | ||
defaultBindingMode: BindingMode.OneWay, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BindingMode should be set to BindingMode.TwoWay.
Added SelectedItemChanged event so that user can get the selected row from the list.