在Telerik RadDatePicker WPF中更改日期格式

时间:2013-10-17 00:31:14

标签: c# wpf xaml telerik datepicker

我无法在telerik datepicker中更改日期格式。 我正在尝试以下程序。 我从This link

找到了以下代码
 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>

但错误是The TelerikDateFormatWorkaround was not found.

你能帮助我吗?

1 个答案:

答案 0 :(得分:2)

您应该在xaml中创建TelerikDateFormatWorkaround的实例:

<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是您定义TelerikDateFormatWorkaround class:

的命名空间
xmlns:local="clr-namespace:TelerikWorkaround"