質問

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);
    }
}
役に立ちましたか?

解決

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}'}"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top