我有一个multitrigger,其条件之一是MultiTrigger似乎并不遵循条件
<Condition Property="Validation.HasError"
Value="True"/>
触发之外,我设置了错误的模板为空,只有在触发的制定者之一做我有
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
但由于某些原因,我还是会得到一个异常,该指数超出范围,即我试图访问一个空的错误集合的元素0。
这似乎与控制,其后台数据我尝试做的东西发生,但我不知道是什么导致它去尝试,即使没有任何错误,以创建工具提示。
编辑:我已经删除尽可能多的东西,以下是剩下的东西。当在数据绑定文本框中输入某些内容然后切换焦点时会出现异常。
在App.xaml中,下应用资源
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError"
Value="True">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
在MainWindow.xaml.cs(这是启动窗口)结合
public MainWindow()
{
InitializeComponent();
this.DataContext = new Bar();
}
在MainWindow.xaml,相关
<TextBox Text="{Binding Foo, ValidatesOnDataErrors=True}"/>
In Bar.cs
public sealed class Bar : IDataErrorInfo, INotifyPropertyChanged
{
// Standard PropertyChanged, OnPropertyChanged removed
// Foo does have a backing field and notifies in the
// setter but those have been removed for brevity
public string Foo {get;set;}
public string Error
{
get { return ""; }
}
public string this[string columnName]
{
get
{
switch (columnName)
{
case "Foo":
if (string.IsNullOrEmpty(Foo))
return "The foo must not be empty.";
return "";
default:
throw new ArgumentException("columnName");
}
}
}
}
发布演示问题的相关代码可能会帮助您解决问题。 –
嗯,我以为我做了,但不知怎的,它似乎已经消失。当我再次使用时,将会添加明天 – Jamie
对于XML和HTML,您需要使用正确的代码格式。我修好了它。 –