public NumberControl() { AutoSizeAxes = Axes.Y; OutlinedNumberBox numberBox; InternalChildren = new[] { numberBox = new OutlinedNumberBox { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, CommitOnFocusLost = true } }; numberBox.Current.BindValueChanged(e => { int?value = null; if (int.TryParse(e.NewValue, out var intVal)) { value = intVal; } current.Value = value; }); Current.BindValueChanged(e => { numberBox.Current.Value = e.NewValue?.ToString(); }); }
public NumberControl() { AutoSizeAxes = Axes.Y; OutlinedNumberBox numberBox; InternalChildren = new[] { numberBox = new OutlinedNumberBox { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, CommitOnFocusLost = true } }; numberBox.Current.BindValueChanged(e => { if (string.IsNullOrEmpty(e.NewValue)) { Current.Value = null; return; } if (int.TryParse(e.NewValue, out int intVal)) { Current.Value = intVal; } else { numberBox.NotifyInputError(); } // trigger Current again to either restore the previous text box value, or to reformat the new value via .ToString(). Current.TriggerChange(); }); Current.BindValueChanged(e => { numberBox.Current.Value = e.NewValue?.ToString(); }); }
public NumberControl() { AutoSizeAxes = Axes.Y; OutlinedNumberBox numberBox; InternalChildren = new[] { numberBox = new OutlinedNumberBox { LengthLimit = 9, // limited to less than a value that could overflow int32 backing. Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, CommitOnFocusLost = true } }; numberBox.Current.BindValueChanged(e => { int?value = null; if (int.TryParse(e.NewValue, out int intVal)) { value = intVal; } current.Value = value; }); Current.BindValueChanged(e => { numberBox.Current.Value = e.NewValue?.ToString(); }); }