Search code examples
c#wpfdatetimepickerxceed

C# xceed DateTimePicker


I am using c#, wpf and the xceed toolkit for more advanced items but now I am struggling to get the value from the picker.

Here is what i did in my xaml:

xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
<xctk:DateTimePicker x:Name="fromDTP"/>

And here is what I try to do in code-behind to get the date:

var datefrom = fromDTP.SelectedDate;

But i think this doesn't work because it shows me that the value is still null...even when i select a date. Am I missing something ?


Solution

  • SelectedDate property belongs to the WPF DatePicker. NOT to the xceed project. You should use Value and you can bind it. See the example below.

    <xctk:DateTimePicker Format="Custom" x:Name="fromDTP"
                    FormatString="MM-dd-yy hh:mm:ss tt"
                    TimeFormat="Custom"
                    TimeFormatString="hh:mm:ss tt"
                    Grid.Row="0" VerticalAlignment="Top" 
                    Value="{Binding Path=CleanLogsDeletionDate, Mode=TwoWay}" Height="30" Width="172" />
    

    And the property changed class:

    public class HelperInfo : INotifyPropertyChanged
    {
        private DateTime m_CleanLogsDeletionDate;
        public DateTime CleanLogsDeletionDate
        {
            get
            {
                return m_CleanLogsDeletionDate;
            }
            set
            {
                if (m_CleanLogsDeletionDate != value)
                {
                    m_CleanLogsDeletionDate = value;
                    OnPropertyChanged();
                }
            }
        }
    
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    
    }
    

    }