开发者

Custom errormessage for property converter

开发者 https://www.devze.com 2023-02-05 20:28 出处:网络
Is it possible to use a ressource to set the errormessage on a property convert error? [Range(0, 10, ErrorMessageResourceName = \"Error\", ErrorMessageResourceTyp开发者_JAVA技巧e = typeof(Properties.

Is it possible to use a ressource to set the errormessage on a property convert error?

[Range(0, 10, ErrorMessageResourceName = "Error", ErrorMessageResourceTyp开发者_JAVA技巧e = typeof(Properties.Resources))]
[DataMember]
public int MyProperty
{
  get; set;
}

The problem occourres if I try to set MyProperty to "aaa". I get an error saying "Cannot convert 'aaa'". It is that message that I wish to customize.


A really good way to do this would be within a Try/Catch statement. The following is in VB.net, as I'm not yet perfectly well versed in VB.

Try 'Your code for setting the property. Catch MessageBox.Show("Your error message text here", "Your Error Title Here", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try

Basically, you are going to create a try/catch statement, with the code for setting the property under "Try". Then, under "Catch", you're going to show a message box.


I found a solution for my problem. I have created an extention for the controls I use in my XAML code (typically a TextBox). In the extention I handle the format exception and find the appropriate resource.

0

精彩评论

暂无评论...
验证码 换一张
取 消