代码之家  ›  专栏  ›  技术社区  ›  Sarathi Jayapal

WPF RadGridView默认日期值为空值

  •  -2
  • Sarathi Jayapal  · 技术社区  · 6 年前

    如何在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>
    

    萨拉提

    2 回复  |  直到 6 年前
        1
  •  2
  •   jegtugado    6 年前

    看看如何实施 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();  
        }  
    }  
    
        2
  •  0
  •   Shahriar Biggo    6 年前

    尝试转换默认值。此处DateTime.MinValue是默认值

    if (EndDate == DateTime.MinValue)
    {
        Response.Write("Null");
    }