public void SetSelectedColorBinding(BareUIInlineColorPickerView pickerView, string propertyPath) { var reg = SetBinding(propertyPath, value => { if (value is CGColor color) { pickerView.SelectedColor = color; } else if (value is byte[] bytes) { pickerView.SelectedColor = BareUIHelper.ToCGColor(bytes); } }); pickerView.SelectionChanged += new WeakEventHandler <CGColor>((sender, color) => { var objAndProperty = reg.GetSourceProperty(); if (objAndProperty != null) { var property = objAndProperty.PropertyInfo; if (property.PropertyType == typeof(byte[])) { reg.SetSourceValue(BareUIHelper.ToColorBytes(color), objAndProperty); } else if (property.PropertyType == typeof(CGColor)) { reg.SetSourceValue(color, objAndProperty); } } }).Handler; }
public override void OnViewModelLoadedOverride() { Title = ViewModel.State == AddClassViewModel.OperationState.Adding ? "Add Class" : "Edit Class"; AddTopSectionDivider(); AddTextField(new UITextField() { Placeholder = "Name", ReturnKeyType = UIReturnKeyType.Done, EnablesReturnKeyAutomatically = true }, nameof(ViewModel.Name), firstResponder: ViewModel.State == AddClassViewModel.OperationState.Adding); AddDivider(); var colorPicker = new BareUIInlineColorPickerView(this, left: 16, right: 16) { TranslatesAutoresizingMaskIntoConstraints = false, AvailableColors = ColorItem.DefaultColors.Select(i => new BareUIInlineColorPickerView.ColorItem(i.Text, BareUIHelper.ToCGColor(i.Color))) }; StackView.AddArrangedSubview(colorPicker); colorPicker.StretchWidth(StackView); colorPicker.SetHeight(44); BindingHost.SetSelectedColorBinding(colorPicker, nameof(ViewModel.Color)); AddSectionDivider(); var partialSemesterSwitch = new BareUISwitch() { TranslatesAutoresizingMaskIntoConstraints = false, Header = "Partial semester class?" }; BindingHost.SetSwitchBinding(partialSemesterSwitch, nameof(ViewModel.IsPartialSemesterClass)); StackView.AddArrangedSubview(partialSemesterSwitch); partialSemesterSwitch.StretchWidth(StackView); partialSemesterSwitch.SetHeight(44); var stackViewStartEndDates = new UIStackView() { Axis = UILayoutConstraintAxis.Vertical }; { AddDivider(stackViewStartEndDates); var startDatePicker = new BareUIInlineDatePicker(this, left: 16, right: 16) { TranslatesAutoresizingMaskIntoConstraints = false, HeaderText = "Start Date" }; BindingHost.SetDateBinding(startDatePicker, nameof(ViewModel.StartDate)); stackViewStartEndDates.AddArrangedSubview(startDatePicker); startDatePicker.StretchWidth(stackViewStartEndDates); startDatePicker.SetHeight(44); AddDivider(stackViewStartEndDates); var endDatePicker = new BareUIInlineDatePicker(this, left: 16, right: 16) { TranslatesAutoresizingMaskIntoConstraints = false, HeaderText = "End Date" }; BindingHost.SetDateBinding(endDatePicker, nameof(ViewModel.EndDate)); stackViewStartEndDates.AddArrangedSubview(endDatePicker); endDatePicker.StretchWidth(stackViewStartEndDates); endDatePicker.SetHeight(44); } AddUnderVisiblity(stackViewStartEndDates, nameof(ViewModel.IsPartialSemesterClass)); AddSectionDivider(); if (ViewModel.IncludesEditingDetails) { var detailsView = new BareUITextView() { TranslatesAutoresizingMaskIntoConstraints = false, Placeholder = "Details" }; BindingHost.SetTextViewTextBinding(detailsView.TextView, nameof(ViewModel.Details)); StackView.AddArrangedSubview(detailsView); detailsView.StretchWidth(StackView); detailsView.SetHeight(130); AddSectionDivider(); } AddDeleteButtonWithConfirmation("Delete Class", ViewModel.Delete, "Delete class?", "Are you sure you want to delete this class and all of its items?"); AddBottomSectionDivider(); BackButtonText = "Cancel"; PositiveNavBarButton = new PopupRightNavBarButtonItem("Save", delegate { Save(); }); base.OnViewModelLoadedOverride(); }