我有一个带有验证规则的TextBox,它位于TabControl的选项卡上.验证规则失败时,默认的ErrorTemplate正确显示(TextBox周围的红色边框).
但是,如果切换到另一个选项卡,然后使用TextBox返回选项卡,则ErrorTemplate hightlight将消失.如果TextBox中有更改,则仍会调用验证规则并返回false,但仍未显示错误突出显示.
只有当文本内容被更改为有效然后再次无效时才会重新亮相.
我希望如果文本内容无效,切换到另一个选项卡并返回保持无效突出显示.任何想要获得这种行为的想法都是最受欢
xaml:
<TextBox Height="35" >
<TextBox.Text>
<Binding Path="pan_id" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<ps:PanIdValidation />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud) 我有一个TextBox实现的对象的属性绑定IDataErrorInfo.我成立Validation.ErrorTemplate的TextBox,并能正常工作.问题是我在a上有这些TabControl,如果我将标签更改为另一个标签然后返回到初始标签(其中TextBox),则验证模板不再显示.它看起来像是经过验证的(就像值是正确的),但实际上并非如此.
这是IDataErrorInfo对象 - 请注意,"正确"值是一个长度为2的字符串:
public class Presenter : IDataErrorInfo
{
public Presenter()
{
this.Property = String.Empty;
}
public string Property { get; set; }
public string Error { get { return null; } }
public string this[string columnName]
{
get
{
if (columnName == "Property")
{
if (this.Property.Length == 2)
return null;
else
return "Invalid property length!";
}
else return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是XAML:
<TabControl …Run Code Online (Sandbox Code Playgroud)