2014-04-29 31 views
0

我有一個XML文件,我將要綁定到一個WPF DataGrid中,我已經成功地做到了如下WPF轉換器不工作

我的問題是,日期是不是在我想和格式快到了爲1966年12月15日,我想這是在15/12/1966

我寫了這個(下)轉換器

進口System.Windows.Data

公共類DateTimeConverter 實現System.Windows.Data.IValueConverter

Public Function Convert(ByVal value As Object, 
         ByVal targetType As System.Type, 
         ByVal parameter As Object, 
         ByVal culture As System.Globalization.CultureInfo) _ 
     As Object Implements System.Windows.Data.IValueConverter.Convert 

    Dim DateValue As DateTime = CType(value, DateTime) 

    Return DateValue.ToShortDateString 

End Function 

Public Function ConvertBack(ByVal value As Object, 
          ByVal targetType As System.Type, 
          ByVal parameter As Object, 
          ByVal culture As System.Globalization.CultureInfo) _ 
     As Object Implements System.Windows.Data.IValueConverter.ConvertBack 

    Dim strValue As String = value 
    Dim resultDateTime As DateTime 
    If DateTime.TryParse(strValue, resultDateTime) Then 
     Return resultDateTime 
    End If 
    Return DependencyProperty.UnsetValue 

End Function 

末級

然後在XAML使用這種如下

    </DataGridTextColumn.Binding> 
       </DataGridTextColumn> 

但是試圖它會拋出一個錯誤,說它不支持轉換fr om字符串。

有人可以讓我知道這裏做錯了什麼。

感謝

回答

1

,您可以嘗試這樣Reference

<TextBlock Text="{Binding Date, StringFormat={}{0:dd/MM/yyyy}}" />