public BooleanEditorControl(IHostResourceProvider hostResource) : base(hostResource) { BooleanEditor = new FocusableBooleanButton(); BooleanEditor.Title = string.Empty; // update the value on 'enter' BooleanEditor.Activated += (sender, e) => { switch (BooleanEditor.State) { case NSCellStateValue.Off: ViewModel.Value = false; break; case NSCellStateValue.On: ViewModel.Value = true; break; } }; AddSubview(BooleanEditor); this.AddConstraints(new[] { NSLayoutConstraint.Create(BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), NSLayoutConstraint.Create(BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), }); }
protected override void OnViewModelChanged(PropertyViewModel oldModel) { base.OnViewModelChanged(oldModel); if (ViewModel == null) { return; } float top = 3; while (this.combinableList.Count > ViewModel.Choices.Count) { var child = this.combinableList.KeyAt(ViewModel.Choices.Count); child.RemoveFromSuperview(); this.combinableList.RemoveAt(ViewModel.Choices.Count); } int i = 0; for (; i < ViewModel.Choices.Count; i++) { var choice = ViewModel.Choices[i]; NSButton checkbox; if (i >= this.combinableList.Count) { checkbox = new FocusableBooleanButton(); checkbox.Activated += SelectionChanged; AddSubview(checkbox); this.AddConstraints(new[] { NSLayoutConstraint.Create(checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top), NSLayoutConstraint.Create(checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create(checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), NSLayoutConstraint.Create(checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, subrowHeight), }); } else { checkbox = this.combinableList.KeyAt(i); } checkbox.Title = choice.Name; this.combinableList[checkbox] = choice; top += subrowHeight; } // Set our tabable order this.firstKeyView = this.combinableList.KeyAt(0); this.lastKeyView = this.combinableList.KeyAt(this.combinableList.Count - 1); SetEnabled(); UpdateAccessibilityValues(); }