WPF RadGridView 默认日期值到空值
WPF RadGridView Default Date Value to Empty Value
如何在 xaml
中将 telerik radgridview 的默认日期值 (1/1/1900) 改写为空
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 Value Converters。
查看:
<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");
}
如何在 xaml
中将 telerik radgridview 的默认日期值 (1/1/1900) 改写为空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 Value Converters。
查看:
<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");
}