我想在DataGrid中的单元格上使用异常验证以及DataGridTextColumn的EditingElementStyle样式来设置带有错误内容的工具提示。发生错误但未被捕获或在WPF中显示。WPF DataGrid验证错误未被捕获
代码和例外如下所示。有人能告诉我我需要解决这个问题吗?
干杯,
Berryl
这里的例外:
System.Windows.Data Error: 8 : Cannot save value from target back to source.
BindingExpression:Path=Allocations[6].Amount; DataItem='ActivityViewModel' (HashCode=-938045583);
target element is 'TextBox' (Name='');
target property is 'Text' (type 'String')
TargetInvocationException:'System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
Domain.Core.PreconditionException: An allocation must be less than one day.
下面是DataGridTextColumn的XAML:
<dg:DataGridTextColumn
....
EditingElementStyle="{StaticResource cellEditStyle}"
Binding="{Binding Allocations[6].Amount, Converter={StaticResource amtConv},
ValidatesOnExceptions=True}"
/>
这里是应该提供工具提示反馈风格他错误:
<Style x:Key="cellEditStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter
Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>