I’m trying to build a form that handles errors and exceptions with mvvm, but xaml handles some errors with out event notifying the view model. For example, there is a textbox that binds to an integer. When you enter a character in the text box ‘value cannot be converted’ error pops. which is fine for most apps, but not for this case because the app I’m writing is in another language and all of the errors are written in that language. I don’t want an error pop in another language.
<Style TargetType="TextBox">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<AdornedElementPlaceholder />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<StackPanel>
<ItemsControl ItemsSource="{TemplateBinding Validation.Errors}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="Red"
Text="{Binding ErrorContent}"></TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
this my error template.
and I use INotifyDataErrorInfo in my view model.
I tried a converter to translate that particular error message ‘value cannot be converted’. but that wasn’t very clean. Is there a better way of doing this?