C# 强制关注例外验证规则
在WPF应用程序上,我使用ExceptionValidationRule对几个文本框进行绑定。 我希望能够留在有ApplicationException的控件上,而不保留它,直到它有正确的数据输入。有可能吗 这是我的密码:C# 强制关注例外验证规则,c#,wpf,xaml,binding,validationrules,C#,Wpf,Xaml,Binding,Validationrules,在WPF应用程序上,我使用ExceptionValidationRule对几个文本框进行绑定。 我希望能够留在有ApplicationException的控件上,而不保留它,直到它有正确的数据输入。有可能吗 这是我的密码: public string strEvtType { get { return m_strEvtType; } set { m_strEvtType = value; i
public string strEvtType
{
get { return m_strEvtType; }
set {
m_strEvtType = value;
if (m_objEvtCode.ReadEvtTypebyType(m_strEvtType) != 0)
{
throw new ApplicationException("Error ! : " + m_strEvtType.Trim() + " don't exist");
}
FirePropertyChangedEvent("strEvtType");
FirePropertyChangedEvent("m_objEvtCode.strDes");
}
我的xaml:
<TextBox Name="TextBox_TypeEvenement" Grid.Column="1" VerticalAlignment="Center" Height="20" LostFocus="TextBox_TypeEvenement_LostFocus">
<TextBox.Text>
<Binding Path="strEvtType">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
我的模板
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="False">
<TextBlock DockPanel.Dock="Right"
Foreground="red"
FontSize="9pt"
Text="{Binding ElementName=MyAdorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
</TextBlock>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder Name="MyAdorner" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
非常感谢:)
致以最良好的祝愿
尼克松