2010-10-05 46 views
0

ConvertDateTime - 返回良好的字符串「01.10.2010」 但數據分析器沒有綁定。不綁定WpfToolKit:通過轉換器的dataPicker

如果我們替換文本框datapicker - 一切運作良好

幫我,代碼:

地址:

xmlns:loc="clr-namespace:StoreBags" 

地址:

<loc:ConvertDateTime x:Key="conkey"/> 

XAML地址:

<my:DataGridTemplateColumn Header="Дата" Width="100"> 
     <my:DataGridTemplateColumn.CellTemplate> 
      <DataTemplate> 
       <DockPanel> 
        <my:DatePicker Text="{Binding date, Converter={StaticResource conkey}}" x:Name="p_datePicker"/> 
       </DockPanel> 
      </DataTemplate> 
     </my:DataGridTemplateColumn.CellTemplate> 
    </my:DataGridTemplateColumn> 

轉換器:

public class ConvertDateTime : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      try 
      { 
       DateTime date = (DateTime)value; 
       return date.ToShortDateString().ToString(); // return "01.10.2010" 
      } 
      catch { return null; } 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      string strValue = value as string; 
      DateTime resultDateTime; 
      if (DateTime.TryParse(strValue, out resultDateTime)) 
      { 
       return resultDateTime; 
      } 
      return DependencyProperty.UnsetValue; 
     } 
    } 

回答

0

嘗試結合selectedDate屬性,而不是

SelectedDate="{Binding date, Converter={StaticResource conkey}}"