新的Telerik UI。net MAUI?开始30天的免费试用

.NET MAUI数字输入命令

NumericInput公开IncreaseCommand而且DecreaseCommand可用于在各自的操作上定义自定义功能。这些命令允许您轻松更改和扩展控件的默认行为。

在下一个示例中,您可以看到如何利用NumericInput命令来实现自动反向功能——当达到最大值时,从最小值开始,反之亦然。

  1. 首先,创建视图模型IncreaseCommand而且DecreaseCommand实现:

    公共类commandviewmodel: NotifyPropertyChangedBase{私有双值;public commandviewmodel () {this。customincreecommand = new命令。IncreaseCommandExecute, this.IncreaseCommandCanExecute); this.CustomDecreaseCommand = new Command(this.DecreaseCommandExecute, this.DecreaseCommandCanExecute); this.Step = 2; this.Value = 0; this.Minimum = 0; this.Maximum = 6; } public double Maximum { get; set; } public double Minimum { get; set; } public double Step { get; set; } public double Value { get { return this.value; } set { this.UpdateValue(ref this.value, value); } } public ICommand CustomDecreaseCommand { get; set; } public ICommand CustomIncreaseCommand { get; set; } private bool DecreaseCommandCanExecute(object arg) { return true; } private void DecreaseCommandExecute(object obj) { double newValue = this.Value - this.Step; if (newValue >= this.Minimum) this.Value = newValue; else this.Value = this.Maximum; } private bool IncreaseCommandCanExecute(object arg) { return true; } private void IncreaseCommandExecute(object obj) { double nextValue = this.Value + this.Step; if (nextValue <= this.Maximum) this.Value = nextValue; else this.Value = this.Minimum; } }
  2. 用相应的绑定定义NumericInput:

          < / telerik: RadNumericInput >

    对于“数字输入命令”示例,请转到sdk浏览器演示应用程序并导航到NumericInput -> Features类别。

另请参阅

在本文中
找不到你需要的帮助?
Baidu
map