Typeconverterattribute namespace


















Assuming the object displayed has a primary identity, it is better for the end user to see the object identity instead of the namespace. In other words, we want to change the PropertyGrid display on the left to the friendlier one on the right: Default view With type converter.

To understand how to go from one to the other, let's look at the simple sample. First, here is the code that produced the default view shown above on the left.

Note that to make this editable, simply create an override for the ConvertFrom method. I have not done this because doing so would require a call to a database to return the object specified by the primary key and I want to keep this illustration as simple and easy to understand as possible.

The System. Here you can see how you can create your own type converter classes. Simply inherit TypeConverter or one of the other 27 base TypeConverter types and implement the overrides as neccessary. Inherit ExpandableObjectConverter if your object property should be displayed on it's own node level.

When the TypeConverter is inadaquate and you must provide your own interface, you simply create a class that derives from Copy Code UITypeEditor and overrides EditValue with some code that shows a form applicable to your content. Now that you've seen how simple it is to get user-friendly views of your object properties in the property grid, you'll want to go on to the next steps that are covered in more detail in other articles on this site. This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves.

If in doubt please contact the author via the discussion board below. Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Tagged as. Didn't work : But then again, neither does AssemblyResolve, with or without typeof.

AddAttributes, and correctly retrieve it using TypeDescriptor. RogerWillcocks is your converter in another assembly by any chance? Perhaps it is not referenced by the one using the attribute? Just figured it out at last. It was the DataBinding. TypeConverters apparently don't get called on unless "formattingEnabled" is true. This worked for me. EnumDescriptionConverter" ] and then it worked everywhere.

The converted is defined in another assembly than the code that is using it. Show 2 more comments. Fadi Fadi 1 1 silver badge 5 5 bronze badges. I am thinking it is most likely to do with it being in different assemblies - I had just tried moving bits around; when I had a PropertyGrid referring to items in another assembly it could no longer use its TypeConverters et al to display the property.

I would be surprised if there was no solution to this though. The root of all evil is a flaw in the TypeDescriptorAttribute implementation. If you want system or WinForms code to use the type converter, this won't help. Make sure there's a DLL reference from this DLL to the one with that type — after you compile it, not just in the project. Or compile with a fresh compiler version which uses Roslyn, it does not ghost out DLL references like the original one.

Add nameof txt. Text , this. Roger Willcocks Roger Willcocks 1, 11 11 silver badges 26 26 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. The parameter that you pass into the LocalizedDescription attribute is the type of your string resource file.

Now when the converter is used it will see the attribute of the enum type, get the resource file, look for the key string that matches the string value of the particular enum value, and return the value from the resource file as the converted string. The major drawback to this approach is that it will only work if the "Name" keys in your resource file match the names of your enum values. This is the only way to reference string values in a resource file without giving each enum a description attribute.

So how do you use this for displaying values? Here is an example In your xaml code you will want to make a data provider to get the values of the enums to your UI element I'm using a ComboBox here Then you will want to make the converter available and template your UI element to use the enum converter.

So here it goes Wow, sorry this is so long. I'm not sure if this is too complex for you but it is another option. Hope it helps! Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 10 months ago. Active 8 years, 10 months ago. Viewed 6k times. I've done this convention on other classes, and it works just fine. Why does putting a typeconverter directly on an enum not work?

GetConverter typeof Enum. Defaintely not related. The solution to the answer in that thread is already implemented above. This question is taking it much further. Add a comment. Active Oldest Votes. Generic; using System.



0コメント

  • 1000 / 1000