Default Silverlight ValidatesOnException Syntax

In my Silverlight 4 MVVM application, I can switch languages ​​at runtime:

public void SetLanguage(string language) { var culture = new CultureInfo(language); Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; // ... } 

For inputs, I simply added "ValidatesOnException = true" in case of problems with the conversion and does the job. But the default exception message refers to my OS culture, not a manually selected one.

In this thread of localizing exception messages, the idea is to change the CurrentCulture and CurrentUICulture that I made. So I'm a little stuck.

What can I do?

Thanks:)

Edit: I tried using a custom converter with a custom exception in the conversion method to verify user input. The problem, the exception in the conversion method is NOT caught by validatesOnException, it interrupts the application.

Edit 2: clarify -> if I have a decimal property associated with a text field and I enter "blabla" in this text field, I want to see that there is a problem, and I want the message to be in runtime, and not the locale OS I cannot throw an exception in my property installer, because I never get there, the default converter creates its own exception before that.

Hope this is clear. If I can help you, please feel free to :)

+7
source share
3 answers

Perhaps you do not change the culture from the very beginning.

I suggest you try the approach mentioned in the first answer in this link:

Change Silverlight Application Culture

0
source

One possible approach is to change the property type to string , even if you store the decimal value behind it. The getter will call ToString on the stored decimal value, and the installer will convert from string to decimal using Decimal.Parse or similar. This approach means you need to do the type conversion yourself, but it will at least give you a little more control.

Your setter may throw exceptions to indicate validation errors. Alternatively, you can use one of the IDataErrorInfo and INotifyDataErrorInfo interfaces to show a validation error. This page provides an example of using IDataErrorInfo and this one has an example of using INotifyDataErrorInfo.

0
source

You can use the custom implementation of ValidationRule and add Binding.ValidationRules . You will have to clear the collection earlier (I'm not sure how to do XAML) and add this rule (how to do this is described on one of the MSDN pages).

This class has a Validate method where you can check and return the error message you want.

0
source