我正在尝试编写一个简单的行为,用于验证输入值是否在某个范围内,其中包括最大和最小值:
<Entry Text="{Binding Quantity, Mode=TwoWay}">
<Entry.Behaviors>
<ui:ValueInRangeValidator x:Name="QtyValidator" MinValue="1" MaxValue="10"/>
</Entry.Behaviors>
</Entry>
这个可以正常运作,但是当我尝试添加绑定,例如:
MaxValue="{Binding MaxVal}"
时,值保持它的默认值。
我在我的行为中使用以下内容:
public static BindableProperty MaxValueProperty =
BindableProperty.Create("MaxValue", typeof(decimal?), typeof(ValueInRangeValidator));
public decimal? MaxValue
{
get { return (decimal?)GetValue(MaxValueProperty); }
set
{
SetValue(MaxValueProperty, value);
OnPropertyChanged();
}
}
我还尝试在BindableProperty上设置属性更改事件,但似乎从未触发。我知道ViewModel是正确的,因为将相同的属性绑定到标签可以显示该值。