【发布时间】:2009-12-16 16:28:11
【问题描述】:
我正在尝试对 DataGrid 中的单元格使用异常验证以及 DataGridTextColumn 的 EditingElementStyle 上的样式来设置带有错误内容的工具提示。发生错误但未在 WPF 中捕获或显示。
代码和异常如下所示。谁能告诉我我需要解决这个问题吗?
干杯,
浆果
这是一个例外:
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>
【问题讨论】:
标签: wpf validation datagrid