A "universal" control for a property (roughly) of any type?

So, I'm just curious, since my research yielded no results, is there a freely accessible control (preferably WPF) that is essentially a β€œuniversal” control for a property of any type?

For example, suppose you create a WYSIWYG form constructor, and you want to support several types of values ​​- strings, bools, ints, datetimes, float, etc. And, of course, lists of any of these types, too ... I wonder if there is already a control that, when attached, will detect the property type and then display the corresponding control type for this type. I.e:

For int, a text box with up / down buttons and checking that it is an integer For date and time, the data collector List datetimes is possibly a custom control that combines the list with a date and time selector and that allows you to add / remove data as needed ...

It is relatively simple to write one, I think, but it is difficult to efficiently handle all the different types, and of course, it could not handle more complex types ...

Does anyone know anything?

+4
source share
3 answers

This type of management is commonly called a PropertyGrid .

Take a look at these controls and see if they fit your needs:

+3
source

This is not an ideal solution for you, but Silverlight has a DataForm that, when bound to an object of a custom type, generates a form with the appropriate controls for the properties. It is not included in WPF, but there is a WPF port for the Silverlight control .

EDIT

I missed part of your question, making it even smaller for you. Although this may still help, so I will leave it here.

0
source

If you roll your own control, you can easily provide this feature and enable best-in-class controls to perform specific tasks, such as numerical editors and date combinations.

At first we were looking for complete control, but, like you, we could not find it. Thus, we made our own with support for more than 15 different types of data display. All control, including comments, is only about 1,500 lines and includes a lot of functionality specific to our application, but we could also combine with various third-party controls.

Another approach that we use in another use case is to create a common control interface (i.e., set value, get value, real, etc.), and then create special user controls that implement this interface.

Then, to perform mass actions on the controls, it is just a matter of cycling through the list of container controls and, if the control implements our interface, performs the action of the interface on this control.

This greatly reduces the amount of code we need to write to perform standard operations for all controls.

0
source

All Articles