Custom StringFormat

2 posts, 0 answers
  1. Tony
    Tony avatar
    12 posts
    Member since:
    Jul 2015

    Posted 01 Apr Link to this post

    Hi Telerik,

    I really like how the TimeSpanPicker has a "StringFormat" property on it, but I'm having challenges getting it to do what I want.

    I want the selected timespan to show as:

    "x Days and y Hours".

    StringFormats like the following aren't working:

    {0:d} Days and {0:h} Hours

    Can you please help me out?  what do I need to do to make it show the way I want it to?

  2. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 05 Apr Link to this post

    Hello Tony,

    You need to set the following StringFormat in order to make the timespan visualize as expected:
    <telerik:RadTimeSpanPicker x:Name="Duration"
                            Value="{Binding SelectedDuration, Mode=TwoWay}"
                            StringFormat="d' Days and 'h' hours'"
                            TimeSpanWatermarkContent="Select duration..." >
        <telerik:RadTimeSpanPicker.TimeSpanComponents>
            <telerik:DayTimeSpanComponent/>
            <telerik:HourTimeSpanComponent/>
            <telerik:MinuteTimeSpanComponent/>
            <telerik:SecondTimeSpanComponent/>
            <telerik:MillisecondTimeSpanComponent/>
        </telerik:RadTimeSpanPicker.TimeSpanComponents>
    </telerik:RadTimeSpanPicker>

    Hope this helps.

    Regards,
    Nasko
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top