Krishna Thota
Krishna Thota

Reputation: 7026

Changing Date format in Telerik RadDatePicker WPF

I cannot change the date format in Telerik DatePicker. I'm trying the below procedure. I found the following code here

public class TelerikDateFormatWorkaround
{
    public CultureInfo CultureWithSwissFormat
    {
        //Hack to get around the fact that there is no custom date format in the Telerik DatePicker
        //http://www.telerik.com/community/forums/wpf/datepicker/changing-dateformat.aspx
        get
        {
            var tempCultureInfo = (CultureInfo) CultureInfo.CurrentCulture.Clone();
            tempCultureInfo.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";
            return tempCultureInfo;
        }
    }
}
<Window.Resources>
    <Style TargetType="telerik:RadDatePicker">
        <Setter Property="Culture" Value="{Binding Source={StaticResource TelerikDateFormatWorkaround}, Path=CultureWithSwissFormat}"/>
    </Style>
</Window.Resources>

But I have the following error The TelerikDateFormatWorkaround was not found.

Can you help me?

Upvotes: 1

Views: 4784

Answers (1)

kmatyaszek
kmatyaszek

Reputation: 19296

You should create instance of TelerikDateFormatWorkaround in xaml:

<Window.Resources>       
    <local:TelerikDateFormatWorkaround x:Key="TelerikDateFormatWorkaround" />

    <Style TargetType="telerik:RadDatePicker">
        <Setter Property="Culture" Value="{Binding Source={StaticResource TelerikDateFormatWorkaround}, Path=CultureWithSwissFormat}"/>
    </Style>
</Window.Resources>

local is namespace where you defined TelerikDateFormatWorkaround class:

xmlns:local="clr-namespace:TelerikWorkaround"

Upvotes: 2

Related Questions