xamdatetimeeditor设置默认当前时间和日期

时间:2014-04-24 09:34:44

标签: wpf xaml infragistics

如何在xamdatetimeeditor中设置默认当前时间和日期而不是默认空白?

下面的代码不会显示当前的日期和时间 它将为空白,直到从xamDateTimeEditor下拉列表中选择日期时间。

在xaml

<igEditors:XamDateTimeEditor 
        Grid.Row="12" Grid.Column="2" x:Name="Date" 
        Visibility="{Binding datetimeVisible, Converter={StaticResource booleanToVisibility}}"
        Height="23" Validation.Error="Validation_Error" Mask="yyyy/mm/dd hh:mm:ss" 
        DropDownButtonDisplayMode="Always"  DisplayMode="IncludeBoth" 
        Value="{Binding DateInitial, UpdateSourceTrigger=PropertyChanged,
                        ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
        Text ="{Binding DateSelected, UpdateSourceTrigger=PropertyChanged,
                        ValidatesOnDataErrors=true, NotifyOnValidationError=true}">
    <igEditors:XamDateTimeEditor.ValueConstraint>
        <igEditors:ValueConstraint 
                MaxInclusive="{x:Static sys:DateTime.Now}" ValidateAsType="DateTime" />
    </igEditors:XamDateTimeEditor.ValueConstraint>
</igEditors:XamDateTimeEditor>

在代码背后

public string Error
{
    get { throw new NotImplementedException(); }
}

public string this[string columnName]
{
    get
    {
        string result = null;
        if (columnName == "DateSelected")
        {
            if (string.IsNullOrEmpty(DateSelected))
            {
                result = "Please select date";
            }
        }
        return result;
    }
}

public DateTime DateInitial
{
    get { return this.dateInitial; }
    set
    {
        this.dateInitial = value;

        this.NotifyPropertyChanged("Date");
        Trace.WriteLine("dateInitial !!!! " + dateInitial);
    }
}

1 个答案:

答案 0 :(得分:2)

我明白了: 将NullText添加到<igEditors:XamDateTimeEditor

NullText="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{}{0:yyyy/MM/dd H:mm:ss}'}"