Home Forums WPF controls Xceed DataGrid for WPF DatePicker value changed

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22847 |

    Is there an event that is raised when the SelectedDate is changed using the calendar?

    Thanks,
    marciak

    Imported from legacy forums. Posted by Marcia (had 4551 views)

    Xceed Support
    Member
    Post count: 5658

    SelectedDate is a dependency property. You can register to the change notification of the DP by using a DependencyPropertyDescriptor.

    DependencyPropertyDescriptor myDescriptor = DependencyPropertyDescriptor.FromProperty( DatePicker.SelectedDateProperty, typeof(DatePicker));

    myDescriptor.AddValueChanged( myDatePicker, new EventHandler( myHandler ) );

    Imported from legacy forums. Posted by Marcus [Xceed] (had 492 views)

    User (Old forums)
    Member
    Post count: 23064

    Hy Marcus,

    into a grid I have a DateTime column.
    the CellEditor is CellEditor.DatePickerEditor.

    How can I retrive the DatePicker object from the cellContentPresenter, in order to register to the change notification of the DP by using a DependencyPropertyDescriptor?
    (I used a snooper and saw that the DatePicker object is under the cellContentPresenter, but I do not know how to get the “myDatePicker” object from there.)

    myDescriptor.AddValueChanged( myDatePicker, new EventHandler( myHandler ) );

    Thanks in advance

    Imported from legacy forums. Posted by winnetou (had 891 views)

    Xceed Support
    Member
    Post count: 5658

    I suggest you redo the CellContentTemplate to use the DatePicker to whose change notification you have subscribed to.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 478 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Jenny,

    I tried to redo the CellContentTemplate in way that you suggest me, but I can not catch the event. See my code:

    DataTemplate dataTemplate = new DataTemplate();
    FrameworkElementFactory dPicker = new FrameworkElementFactory(typeof(DatePicker));

    Binding b = new Binding();
    dPicker.SetBinding(DatePicker.SelectedDateProperty, b);
    dataTemplate.VisualTree = dPicker;

    I tried 2 ways to add a handler for DatePicker:

    1) dPicker.AddHandler(DatePicker.LostFocusEvent, new RoutedEventHandler(SelectedDateChanged));

    But I can’t catch the event.

    2) DependencyPropertyDescriptor myDescriptor = DependencyPropertyDescriptor.FromProperty
    (DatePicker.SelectedDateProperty, typeof(DatePicker));
    myDescriptor.AddValueChanged(dPicker, new EventHandler(SelectedDateChanged));

    Here, the AddValueChanged method expects to received a DependencyObject object at first parameter. But we have a FrameworkElementFactory object.

    More that, if I replace the CellEditorContent for a column and use a DatePicker in DataTemplate, than the ToggleButton of DatePicker is always visible. I can not found how to hide this button.

    Thanks,
    winnetou

    Imported from legacy forums. Posted by winnetou (had 1478 views)

    Xceed Support
    Member
    Post count: 5658

    Try something like this:

    <code>
    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”OrderDate”>
    <xcdg:Column.CellEditor>
    <xcdg:CellEditor>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <xcdg:DatePicker SelectedDate=”{xcdg:CellEditorBinding}”
    PreviewMouseUp=”DatePicker_PreviewMouseUp”/>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>
    </xcdg:Column.CellEditor>
    </xcdg:Column>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </code>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 5606 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.