2013-10-17 103 views
1

我無法更改telerik datepicker中的日期格式。 我在嘗試下面的過程。 我發現從This link在Telerik RadDatePicker中更改日期格式WPF

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.

你能幫助我嗎?

+0

注意您鏈接狀態樣品中評論「將它添加到該用戶控件資源」。你在做什麼?代碼段是什麼樣的? –

+0

在'TargetType =「telerik:RadDatePicker」' –

回答

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類:

xmlns:local="clr-namespace:TelerikWorkaround"