默认情况下,Validation.ErrorTemplate在WPF只是一个小红色边框没有任何ToolTip.
在Silverlight 4中,验证错误很好地开箱即用.
以下是Silverlight 4和WPF中出现的验证错误的比较
Silverlight 4

WPF

请注意WPF版本的平坦,无聊的外观与我认为的Silverlight外观相比.
WPF框架中是否存在任何类似的验证样式/模板,或者是否有人创建了很好的样式验证模板,如上面的Silverlight版本?或者我是否必须从头开始创建它们?
如果有人想尝试一下,可以使用以下代码重现上面的验证错误,适用于Silverlight和WPF
主窗口/ MainPage.xaml中
<StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Top">
<TextBox Text="{Binding Path=TextProperty, Mode=TwoWay, ValidatesOnExceptions=True}"/>
<Button Content="Tab To Me..." Margin="20,0,0,0"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
主窗口/ MainPage.xaml.cs中
public MainWindow/MainPage()
{
InitializeComponent();
this.DataContext = this;
}
private string _textProperty;
public string TextProperty
{
get { return _textProperty; }
set
{
if (value.Length > 5)
{
throw new Exception("Too many characters");
}
_textProperty = value;
} …Run Code Online (Sandbox Code Playgroud)