我想在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>