Use `BindValueChanged` instead of setting the value in property setter

This commit is contained in:
Henry Lin 2021-06-28 11:20:00 +08:00
parent 0cceef8da5
commit 3d19364a71
1 changed files with 8 additions and 14 deletions

View File

@ -20,22 +20,18 @@ private sealed class NumberControl : CompositeDrawable, IHasCurrentValue<int?>
{
private readonly BindableWithCurrent<int?> current = new BindableWithCurrent<int?>();
private readonly OutlinedNumberBox numberBox;
public Bindable<int?> Current
{
get => current;
set
{
current.Current = value;
numberBox.Text = value.Value.ToString();
}
get => current.Current;
set => current.Current = value;
}
public NumberControl()
{
AutoSizeAxes = Axes.Y;
OutlinedNumberBox numberBox;
InternalChildren = new[]
{
numberBox = new OutlinedNumberBox
@ -55,13 +51,11 @@ public NumberControl()
current.Value = value;
});
}
protected override void Update()
{
base.Update();
if (Current.Value == null)
numberBox.Current.Value = "";
Current.BindValueChanged(e =>
{
numberBox.Current.Value = e.NewValue?.ToString();
});
}
}
}