This project has moved. For the latest updates, please go here.

PropertyGrid DateTime property updating issue

Oct 13, 2015 at 8:21 AM
Hi. There is a property of type DateTime in a propertygrid. Here is a code:
<xctk:PropertyGrid x:Name="_propertyGrid" Margin="10" AutoGenerateProperties="True" SelectedObject="{Binding}">
                                
</xctk:PropertyGrid>
public class DateEditor : Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor
    {
        public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem)
        {
            
            DateTimeUpDown temp1 = new DateTimeUpDown();
            temp1.Format = DateTimeFormat.Custom;
            temp1.FormatString = "dd.MM.yyyy hh:m:ss";
                       
            //create the binding from the bound property item to the editor
            var _binding = new Binding("Value"); //bind to the Value property of the PropertyItem
            _binding.Source = propertyItem;
            _binding.ValidatesOnExceptions = true;
            _binding.ValidatesOnDataErrors = true;
            _binding.Mode = BindingMode.TwoWay;

            BindingOperations.SetBinding(temp1, DateTimeUpDown.TextProperty, _binding);
            
            return temp1;
        }
    }

public class CustomAttributEditorPerson : INotifyPropertyChanged
    {
        private DateTime FDate;
        
        [Category("Information")]
        [DisplayName("Date")]
        //This custom editor is a Class that implements the ITypeEditor interface
        [RefreshProperties(RefreshProperties.All)]
        [Editor(typeof(FirstNameEditor), typeof(FirstNameEditor))]
        public DateTime Date
        {
            get
            {
                return this.FDate;
            }
            set
            {
                this.FDate = value;
                NotifyPropertyChanged("Date");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));

            }
        }
    }
public partial class MainWindow : Window
    {
        CustomAttributEditorPerson temp = new CustomAttributEditorPerson();

        public MainWindow()
        {
            InitializeComponent();

            temp.Date = new DateTime(2020, 7, 7, 0, 1, 2);

            _propertyGrid.SelectedObject = temp;
        }
When app is started I see current date instead of required 7.7.2020. Changing of the property temp.Date doesn't reflected in propertygrid. The following code doesn't lead to the result:
private void Button_Click_1(object sender, RoutedEventArgs e)
        {
              temp.Date = new DateTime(2030, 8, 7, 0, 1, 2);   
              _propertyGrid.Update();        
        }
What should be done to reflect the changes of tempDate in propertygrid?
Thanks for assistance.
Oct 13, 2015 at 11:11 AM
Edited Oct 13, 2015 at 11:12 AM
I replaced
BindingOperations.SetBinding(temp1, DateTimeUpDown.TextProperty, _binding); 
with
BindingOperations.SetBinding(temp1, DateTimeUpDown.ValueProperty, _binding); 
and everything is working fine now.