Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class SelectableRowComponent : Grid
- {
- private ViewBinder<ISelectableItemViewModel> _viewBinder;
- public SelectableRowComponent()
- {
- InitializeComponent();
- _viewBinder = this.CreateViewBinder<ISelectableItemViewModel>(Bind);
- }
- private bool _isSelected;
- public bool IsSelected
- {
- get => _isSelected;
- set
- {
- _isSelected = value;
- OnIsSelectedChanged(_isSelected);
- }
- }
- private void Bind()
- {
- using var bindingSet = _viewBinder.CreateBindingSet();
- bindingSet.Bind(this).For(v => v.BindTap()).To(vm => vm.SelecteCommand);
- bindingSet.Bind(this).For(v => v.IsSelected).To(vm => vm.IsSelected);
- bindingSet.Bind(RowImage).For(v => v.Source).To(vm => vm.Icon);
- bindingSet.Bind(RowImage).For(v => v.BindTintColor()).To(vm => vm.IsSelected)
- .WithBoolToColorConversion(AppColor.Dark, AppColor.Blue);
- bindingSet.Bind(TextLabel).For(v => v.Text).To(vm => vm.Title);
- bindingSet.Bind(CountFrame).For(v => v.IsVisible).To(vm => vm.Count)
- .WithConversion((int? count) => count is not null && count > 0);
- bindingSet.Bind(CountLabel).For(v => v.Text).To(vm => vm.Count);
- bindingSet.Bind(IsSelectedImage).For(v => v.IsVisible).To(vm => vm.IsSelected);
- }
- private void OnIsSelectedChanged(bool isSelected)
- {
- if (isSelected)
- {
- TextLabel.TextColor = AppColor.Blue.ToFormsColor();
- CountFrame.BackgroundColor = AppColor.Blue.ToFormsColor();
- return;
- }
- TextLabel.TextColor = _viewBinder.ViewModel.Count == 0 ? AppColor.DarkLight.ToFormsColor() : AppColor.DarkDeep.ToFormsColor();
- CountFrame.BackgroundColor = AppColor.DarkLight.ToFormsColor();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment