private void BaseViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "BindingBodyExercises") { SelectTrainingExercisesViewModel viewModel = sender as SelectTrainingExercisesViewModel; if (viewModel != null) { TouchViewCell touchViewCell; BodyExerciseSection.Clear(); foreach (var bindingBodyExercise in viewModel.BindingBodyExercises) { touchViewCell = new TouchViewCell() { IsIndicatorVisible = false, BindingContext = bindingBodyExercise, ImageWidthRequest = 100, ImageHeightRequest = 100, Height = 100 }; touchViewCell.Tapped += BodyExerciseItemTapped; touchViewCell.SetBinding(TouchViewCell.IsCheckedVisibleProperty, (BindingBodyExercise source) => source.Selected); touchViewCell.SetBinding(TouchViewCell.ImageProperty, (BindingBodyExercise source) => source.Image); touchViewCell.SetBinding(TouchViewCell.ValueProperty, (BindingBodyExercise source) => source.Name); BodyExerciseSection.Add(touchViewCell); } } } }
private void TrainingWeekPage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "BindingWeekTrainingDays") { TrainingWeekViewModel viewModel = sender as TrainingWeekViewModel; if (viewModel != null) { TouchViewCell touchViewCell; DaySection.Clear(); foreach (var bindingWeekTrainingDay in viewModel.BindingWeekTrainingDays) { touchViewCell = new TouchViewCell() { IsIndicatorVisible = true, BindingContext = bindingWeekTrainingDay, TitleTextColor = Color.Red, ValueTextColor = Color.Red }; touchViewCell.Tapped += DayCellTaped; touchViewCell.SetBinding(TouchViewCell.ValueProperty, (BindingWeekTrainingDay source) => source.Label); var trigger = new DataTrigger(typeof(Label)); trigger.BindingContext = bindingWeekTrainingDay; trigger.Binding = new Binding("TrainingDayExist"); trigger.Value = true; var setter = new Setter(); setter.Property = Label.TextColorProperty; setter.Value = Color.FromHex("#337ab7"); trigger.Setters.Add(setter); touchViewCell.SetValueTrigger(trigger); trigger = new DataTrigger(typeof(Label)); trigger.BindingContext = bindingWeekTrainingDay; trigger.Binding = new Binding("TrainingDayExist"); trigger.Value = true; setter = new Setter(); setter.Property = Label.TextColorProperty; setter.Value = Color.FromHex("#337ab7"); trigger.Setters.Add(setter); touchViewCell.SetTitleTrigger(trigger); var menuItem = new MenuItem(); menuItem.SetBinding(MenuItem.TextProperty, new Binding(path: "SwitchDayLabel", source: viewModel)); menuItem.BindingContext = bindingWeekTrainingDay; menuItem.Command = viewModel.SwitchTrainingDayCommand; menuItem.SetBinding(MenuItem.CommandParameterProperty, new Binding(path: "DayOfWeek", source: bindingWeekTrainingDay)); touchViewCell.ContextActions.Add(menuItem); menuItem = new MenuItem(); menuItem.SetBinding(MenuItem.TextProperty, new Binding(path: "CopyDayLabel", source: viewModel)); menuItem.BindingContext = bindingWeekTrainingDay; menuItem.Command = viewModel.CopyTrainingDayCommand; menuItem.SetBinding(MenuItem.CommandParameterProperty, new Binding(path: "DayOfWeek", source: bindingWeekTrainingDay)); touchViewCell.ContextActions.Add(menuItem); DaySection.Add(touchViewCell); } } } }
public void BodyExerciseItemTapped(object sender, EventArgs e) { TouchViewCell touchViewCell = sender as TouchViewCell; if (touchViewCell != null && touchViewCell.BindingContext != null) { var bindingBodyExercise = touchViewCell.BindingContext as BindingBodyExercise; var selectTrainingExercisesViewModel = _viewModel as SelectTrainingExercisesViewModel; if (selectTrainingExercisesViewModel != null) { selectTrainingExercisesViewModel.SelectBodyExerciseCommand.Execute(bindingBodyExercise); } } }