/// <summary> /// Creates the content control for the cell. /// </summary> /// <remarks> /// The control returned may be reused for other cells, so it is ideal to use MVVM data binding using /// BindDataContext() /// methods of your controls. /// This should return the same control for each row, otherwise the incorrect control may be shown on certain cells. /// </remarks> /// <param name="args">Cell arguments.</param> public override Control OnCreate(CellEventArgs args) { if (ItemBinding == null) { return(null); } var checkBox = new CheckBox(); checkBox.CheckedBinding.BindDataContext(ItemBinding); var label = new Label { Wrap = WrapMode.None, VerticalAlignment = VerticalAlignment.Center }; label.MouseDoubleClick += (sender, e) => checkBox.Checked = !checkBox.Checked; label.Bind(c => c.TextColor, args, a => a.CellTextColor); label.TextBinding.BindDataContext(ItemBinding.Convert(r => Convert.ToString(r))); return(new TableLayout { Spacing = new Size(5, 0), Rows = { new TableRow(new TableCell(label, true), checkBox) } }); }
/// <summary> /// Creates the content control for the cell. /// </summary> /// <remarks> /// The control returned may be reused for other cells, so it is ideal to use MVVM data binding using /// BindDataContext() /// methods of your controls. /// This should return the same control for each row, otherwise the incorrect control may be shown on certain cells. /// </remarks> /// <param name="args">Cell arguments.</param> public override Control OnCreate(CellEventArgs args) { if (ItemBinding == null) { return(null); } var picker = new ColorPicker(); picker.ValueBinding.BindDataContext(ItemBinding); if (!ShowHex) { return(picker); } var mask = ShowAlpha ? "\\#>AAAAAAAA" : "\\#>AAAAAA"; Control value; if (HexEditable) { var textBox = new MaskedTextBox { Provider = new FixedMaskedTextProvider(mask), InsertMode = InsertKeyMode.Overwrite, BackgroundColor = Colors.Transparent, ShowBorder = false }; textBox.TextChanging += (sender, e) => { e.Cancel = !e.Text.ToCharArray().Select(r => r.ToString()).All("0123456789abcdefABCDEF".Contains); }; var colorBinding = textBox.Bind(c => c.TextColor, args, a => a.CellTextColor); textBox.TextBinding.BindDataContext(ItemBinding.Convert(v => v.ToHex(ShowAlpha), v => { Color c; Color.TryParse(v, out c); return(c); })); textBox.GotFocus += (sender, e) => { colorBinding.Mode = DualBindingMode.Manual; textBox.BackgroundColor = SystemColors.ControlBackground; textBox.TextColor = SystemColors.ControlText; }; textBox.LostFocus += (sender, e) => { textBox.BackgroundColor = Colors.Transparent; colorBinding.Mode = DualBindingMode.TwoWay; colorBinding.Update(); }; value = textBox; } else { var label = new Label(); label.Bind(c => c.TextColor, args, a => a.CellTextColor); label.TextBinding.BindDataContext(ItemBinding.Convert(v => v.ToHex(ShowAlpha), v => { Color c; Color.TryParse(v, out c); return(c); })); value = label; } return(new StackLayout { Orientation = Orientation.Horizontal, VerticalContentAlignment = VerticalAlignment.Stretch, Items = { new StackLayoutItem(value, expand: true), picker } }); }