触发ToolTip-Through按钮而不是动态外观
本文关键字:动态 外观 ToolTip-Through 按钮 触发 | 更新日期: 2023-09-27 18:24:03
我正试图让我的RadMaskedTextBox出现验证错误,目前我可以做到这一点,但它是动态的,我想改变它。
如果我仅设置范围<250,我把500放在它将触发的文本框中,验证错误就会出现。
我希望发生的是只有当按下我的按钮时才会发生验证错误。我可以问一下我该如何转换成那样吗?
Xaml
<ControlTemplate x:Key="validationTemplate">
<DockPanel>
<AdornedElementPlaceholder />
<TextBlock FontSize="20" Foreground="Red">Error!</TextBlock>
</DockPanel>
</ControlTemplate>
<controls:RadMaskedCurrencyInput
x:Name="radMaskedCurrencyInput"
InputBehavior="Insert"
Validation.ErrorTemplate="{StaticResource validationTemplate }"
Value="{Binding Path=DecimalValue,
ValidatesOnDataErrors=True,
ValidatesOnExceptions=True,
NotifyOnValidationError=false,
UpdateSourceTrigger=PropertyChanged}" />
<Button Content="Execute" cal:Message.Attach="[Click] = [ExecuteMessage]"/>
ViewModel:
private decimal decimalValue;
public decimal DecimalValue
{
get { return decimalValue; }
set
{
if (value > 250)
{
throw new ValidationException("Value cannot be greater than 250.");
}
else
decimalValue = value;
this.OnPropertyChanged("DecimalValue");
}
}
如果代码隐藏是可接受的:
设置UpdateSourceTrigger=Explicit
,然后单击按钮时:
private void Button_Click(object sender, RoutedEventArgs e)
{
BindingExpression be = radMaskedCurrencyInput.GetBindingExpression(RadMaskedCurrencyInput.ValueProperty);
be.UpdateSource();
}
请参阅MSDN UpdateSourceTrigger枚举
将UpdateSourceTrigger值设置为Explicit时,只有当应用程序调用UpdateSource方法时,源值才会更改。