[英]WPF RadGridView Default Date Value to Empty Value
如何覆蓋 Telerik radgridview 的默認日期值 (1/1/1900) 以在 xaml 中清空
xaml 綁定就像:
<telerik:GridViewDataColumn Header="Estimated Start On" DataMemberBinding="{Binding EstdStartDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat=N2}" Width="100" IsFilterable="False" IsGroupable="False">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding EstdStartDate}" Height="30" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
謝謝,薩拉蒂
看看如何實現WPF 值轉換器。
看法:
<telerik:GridViewDataColumn DataMemberBinding="{Binding DateColumn, Converter={StaticResource MyDateConverter}" IsReadOnly="True">
轉換器:
public class MyDateConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime)
{
DateTime test = (DateTime) value;
if (test.Year > 1900) // If year is greater than 1900 then display
{
string date = test.ToString("d/M/yyyy"); // Your date format
return date;
}
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
嘗試轉換默認值。 這里 DateTime.MinValue 是默認值
if (EndDate == DateTime.MinValue)
{
Response.Write("Null");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.