Scripting - Server Side (PHP, Perl, etc.Windows Presentation Foundation (WPF) & XAML forum.NET Installation and Configuration Issues Public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) Public override bool GetPropertiesSupported(ITypeDescriptorContext iContext) String tokens = ((string) iValue).Split(new char ) Return base.ConvertFrom(iContext, iCulture, iValue) For example, you should pass 'Blue', not '' or 'Color.Blue', to the ConvertFrom method. Return base.CanConvertFrom(iContext, iSourceType) When converting from a string to a Color the ColorConverter expects the unqualified color name otherwise, an exception will occur in the conversion process. Public override bool CanConvertFrom(ITypeDescriptorContext iContext, Type iSourceType) Public class ColorConverter : TypeConverter Last edited by September 7th, 2008 at 11:55 AM. I want to avoid the application crash if the user enters invalid data.īasically, forget about the TypeConverter, I just want to know how to get the property grid to validate the text data, and that if the data is invalid, get it to show the warning window. The property grid does not handle it and as a result the application crashes. Now if the user enters invalid text data, ConvertFrom() of course throws an exception because it fails to parse the data. I implemented the functions and the property grid doesn't even access those methods when modifying the text next to the value in the property grid, only if you modifiy one of the sub properties (which does make sense).Īfter modifying the text datam all the property grid does is call the ConvertFrom() method. Moreover, implementing these functions does not solve my problem. It modifies the already existing instance you gave it instead of creating a fresh new one, that's it. You just return false in the GetCreateInstanceSupported() method and the Property Grid does just fine without it. This function is not needed for the Property Grid to work. How can I get that popup to show my error message so the user can correct his mistake instead of that crash? ![]() If I do the same in my TypeConverter, I get an unhandled exception and the application terminates. I am trying to get the same behavior and I can't figure out how.ĭisassembling shows an invalid input string will return an Argument Exception. NET (for example ), entering invalid data pops up a dialog box explaining why the format is invalid. ![]() What I did in this case is throw an Exception, thinking the property grid would catch it to display the exception message to the user.įor types provided in. However, if the user provides an invalid string format, the TypeConverter has to react in some way to let the UI know the data provided by the user is invalid. Converted from a string, the format has to be 'red, green, blue, alpha'.Įverything works fine if the string provided to the TypeConverter is valid. The type to convert is actually a in-house Color struct. I am implementing TypeConverters for my custom type so it works appropriately in the Property Grid.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |