2010-10-05 7 views
0

ConvertDateTime - renvoie la bonne chaîne "01.10.2010" mais le datapicker n'est pas lié.Not Binding WpfToolKit: dataPicker via le convertisseur

si nous remplaçons datapicker sur zone de texte - tout fonctionne bien

aide-moi, le code:

ajouter:

xmlns:loc="clr-namespace:StoreBags" 

ajouter:

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

XAML ajouter:

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

Converter:

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; 
     } 
    } 

Répondre

0

Essayez la liaison à la propriété SelectedDate à la place

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