【问题标题】:Changing Date format in Telerik RadDatePicker WPF在 Telerik RadDatePicker WPF 中更改日期格式
【发布时间】:2013-10-17 00:31:13
【问题描述】:

我无法更改 Telerik DatePicker 中的日期格式。 我正在尝试以下程序。 我找到了以下代码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>

但我有以下错误The TelerikDateFormatWorkaround was not found.

你能帮帮我吗?

【问题讨论】:

  • 请注意您链接的示例中的注释声明“将其添加到用户控件资源”。你在哪里做这个?代码段长什么样子?
  • TargetType="telerik:RadDatePicker"

标签: c# wpf xaml telerik datepicker


【解决方案1】:

您应该在 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 类的命名空间:

xmlns:local="clr-namespace:TelerikWorkaround"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    相关资源
    最近更新 更多