Exemple #1
0
            public UIClassView()
            {
                const int CIRCLE_HEIGHT = 18;

                _circle      = new CAShapeLayer();
                _circle.Path = CGPath.EllipseFromRect(new CGRect(16, 12, CIRCLE_HEIGHT, CIRCLE_HEIGHT));
                BindingHost.SetColorBinding(_circle, nameof(ViewItemClass.Color));
                base.Layer.AddSublayer(_circle);

                _labelName = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font  = UIFont.PreferredTitle3,
                    Lines = 1
                };
                BindingHost.SetLabelTextBinding(_labelName, nameof(ViewItemClass.Name));
                this.Add(_labelName);
                _labelName.StretchWidthAndHeight(this, left: CIRCLE_HEIGHT + 16 + 16, right: 16);

                this.SetHeight(44);
            }
        public UIEditClassScheduleView()
        {
            base.BackgroundColor = new UIColor(235f / 255f, 1);

            var headerView = new UIControl()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            {
                const int CIRCLE_HEIGHT = 18;

                _circle      = new CAShapeLayer();
                _circle.Path = CGPath.EllipseFromRect(new CGRect(8, 3, CIRCLE_HEIGHT, CIRCLE_HEIGHT));
                BindingHost.SetColorBinding(_circle, nameof(ViewItemClass.Color));
                headerView.Layer.AddSublayer(_circle);

                _labelName = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font  = UIFont.PreferredTitle3,
                    Lines = 1
                };
                BindingHost.SetLabelTextBinding(_labelName, nameof(ViewItemClass.Name));
                headerView.Add(_labelName);
                _labelName.StretchWidthAndHeight(headerView, left:  CIRCLE_HEIGHT + 8 + 8, right: 8);

                headerView.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { OnRequestEditClass(this, DataContext as ViewItemClass); }).Handler;
            }
            this.Add(headerView);
            headerView.StretchWidth(this);

            // Times
            var stackViewTimes = new UIStackView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis    = UILayoutConstraintAxis.Vertical,
                Spacing = 8
            };

            {
                _timesAdapter = new BareUIStackViewItemsSourceAdapter <UIEditClassScheduleTimeView>(stackViewTimes);
                _timesAdapter.OnViewCreated += _timesAdapter_OnViewCreated;
            }
            this.Add(stackViewTimes);
            stackViewTimes.StretchWidth(this);

            // Button
            var buttonAdd = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonAdd.SetTitle("Add Time", UIControlState.Normal);
            buttonAdd.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { OnRequestAddTime?.Invoke(this, DataContext as ViewItemClass); }).Handler;
            this.Add(buttonAdd);
            buttonAdd.StretchWidth(this, left: 8, right: 8);

            this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-8-[headerView]-8-[stackViewTimes]-8-[buttonAdd]-8-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                        "headerView", headerView,
                                                                        "stackViewTimes", stackViewTimes,
                                                                        "buttonAdd", buttonAdd)));
        }