Question

How to set default current time and date in xamdatetimeeditor instead of default blank?

My code below won't show the current date and time.
It will be blank until date time are chosen from xamDateTimeEditor drop down.

In 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>

In code behind

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);
    }
}
Was it helpful?

Solution

I figured it out : Add NullText to the <igEditors:XamDateTimeEditor

NullText="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{}{0:yyyy/MM/dd H:mm:ss}'}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top