Specify the display format for the property

3 posts, 1 answers
  1. TechInsights
    TechInsights avatar
    5 posts
    Member since:
    Mar 2013

    Posted 08 Aug 2013 Link to this post

    Hello everyone,

    Is it possible to specify the display format for a property in the PropertyGrid?

    I've tried the [DisplayFormat], but neither DataFormatString nor NullDisplayText seems to be making any difference whatsoever.

    In my particular case, I want the DateTime property to be displayed as 'yyyy - MM - dd', but (as I mentioned), decorating the property with [DisplayFormat(DataFormatString = "yyyy - MM - dd")] doesn't work.

    As far as I have noticed, PropertyGrid selects RadDateTimePicker for DateTime types by default, but for some dates I'd like the 'date' part only. I don't care much about editing (although that would be nice too), but it would be great to adjust the display for read-only property grids.

    Is there any way to make that work?

    (Controls version used: 2013.2.724)
  2. Answer
    Maya avatar
    4062 posts

    Posted 09 Aug 2013 Link to this post


    The thing is that string format of the binding should be set differently in RadDateTimePicker (the default editing element for DateTime properties). Check out this article for a reference.  What you can try is to define the property definition like: 

                    <telerik:PropertyDefinition Binding="{Binding Established, StringFormat=\{0:MM/dd/yyyy\}}"  IsReadOnly="True">
                                <telerik:RadDatePicker SelectedDate="{Binding Established}" IsReadOnly="{Binding IsReadOnly}"/>

    Is that approach suitable for your sceanrio ?

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. TechInsights
    TechInsights avatar
    5 posts
    Member since:
    Mar 2013

    Posted 27 Aug 2013 Link to this post

    I didn't want to specify separate XAML views for property grids, but to re-use one auto-generated property grid view I have.

    Your link pointed me in the right direction though, thanks!

    I ended up hooking to OnFieldLoaded of the grid and checking the content. Then I get to the 'Binding.StringFormat' and set the DateTimeFormat in the CultureInfo of the date picker. It's a hack, but it works...
Back to Top