This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Again, Is there a way to have nullable types supported? Currently not getting any editor if the property type is nullable. Thanks, Kavan |
|
|
You can do this up to a point using property editors e.g. <ms:PropertyEditor DeclaringType="{x:Type t:Person}" However the default editors do not currently provide a way of setting the value to null. You would need to create a custom property editor if you needed users to be able to set the value back to null. I will look into providing type-level support using the default editors. |
|
|
Hi Ivan, I'm new in my expermenting with WPF, but I've been doing UI dev in Windows since the mid 90s. And what always was a solution for me, was to create a subclass of a given control. So say in this situation, could one create a wrapper maybe with a null button on the side and the actual editor embedded in it. I would imagine that this could be possible in WPF using a panel and then attaching the given editor to its content property. But time is, of course, limited (that's why I'm using the PG Let me know your thoughts and if this in your opinion would be a road worth travelling (hopefully not long). Many thanks, Kavan |
|
|
Yes, I think you could do that by having your editor DataTemplate contain a "null button" and a ContentControl. The ContentControl's ContentTemplate would be set to the appropriate editor key. Caveat: I haven't tried this, though internally we do something very similar to attach the little "remove from collection" buttons to collection elements, so I'm pretty confident. When we add nullable support within the product, I would like to make the user experience more seamless e.g. for a text editor, an empty string would get mapped to null, for a combo box or radio group there would be a special "null" selection with a caption like "(No value)," for a checkbox it would be the intermediate state, etc. But this will requires enhancing each of the editors or adding new ones to provide appropiate null handling. So if you need this today and your users will understand it, I would go for the "null button" approach as the quickest solution. |
|
|
Hi Kavan, Just to let you know, with the support for struct type editors in the next nightly build, it is now possible to build your own nullable type editors, though some assembly is required. The first thing you will need is a way to talk about nullable types in XAML, so that you can specify a nullable type as the EditedType of a type editor. To do this, create a markup extension something like this: public class NullableExtension : MarkupExtension Now hook up a type editor as follows: <ms:TypeEditor EditedType="{local:Nullable sys:Int32}" And your DataTemplate will need to wire up the appropriate UI for nullability. In my proof of concept, I used a plain old text box, but added a value converter to convert an empty string to the null value: public class NullifyingValueConverter : IValueConverter You could equally well use a "null button" or whatever UI is appropriate to the semantics of null values in your application; this is just an example. As mentioned on the other thread, struct type editors are at an early stage right now, so please let me know if you run into any issues. |
|