2009-11-20 53 views

回答

5

執行下列操作(在Silverlight 4):

1)的DataContext的綁定屬性必須是可空(或日期時間)

2)在XAML的結合特性類似於設置TargetNullValue = '':

Text="{Binding DocumentDate, Mode=TwoWay, StringFormat='yyyy-MM-dd', TargetNullValue=''}" 
0

研究同樣的問題時發現了這一點。這是我如何修復它,因爲它沒有被標記。

我已經使用轉換器,它將值轉換爲null,如果它只是一個空的數據時間對象。

public class DateTimeToNullConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      DateTime dt = new DateTime(); 
      if (dt.Equals(value)) return null; 
      return value; 
     } 
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      return value; 
     } 
    } 

XAML:

SelectedValue="{Binding CurrentContractRenewal.ExpiryDate, Mode=TwoWay, Converter={StaticResource DateTimeToNullConverter}}" 
相關問題