-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Came from discussion here: #4206 (review)
Describe the bug
DataGridTemplateColumn is hard to customize as it expects to take DataTemplates nicely from XAML, but then has overrides for a subclass on its methods like PrepareCellForEdit and CancelCellEdit vs. having event based properties. To customize this behavior you have to hook into PreparingCellForEdit event on the DataGrid and then look for the specific column you want vs. having registered the event on the column directly for the one case you may want to override.
Expected behavior
Able to modify the behavior of a base DataGridTemplateColumn without sub-classing.
Additional context
I propose we add two new events to the DataGridTemplateColumn class (or maybe even the base DataGridColumn: PrepareCellForEdit and CancelCellEdit which could be called after the subclass has been called in the Internal methods here:
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridColumn.cs
Lines 987 to 990 in 0ee2c84
| internal void CancelCellEditInternal(FrameworkElement editingElement, object uneditedValue) | |
| { | |
| CancelCellEdit(editingElement, uneditedValue); | |
| } |
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridColumn.cs
Lines 1258 to 1261 in 0ee2c84
| internal object PrepareCellForEditInternal(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) | |
| { | |
| return PrepareCellForEdit(editingElement, editingEventArgs); | |
| } |
The sender would be the column and we could construct event args which contain the returned object from the subclass, the editing element, and the other editing args?
This would make it easier to customize a specific column (and/or also have a general override behavior for every column) without having to continually check for specific columns in the main DataGrid PreparingCellForEdit event?
Currently what we have to do:
dataGrid.PreparingCellForEdit += DataGrid_PreparingCellForEdit;
private void DataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
if (e.Column is DataGridTemplateColumn column && (string)column?.Tag == "First_ascent" &&
e.EditingElement is CalendarDatePicker calendar)
{
calendar.IsCalendarOpen = true;
}
}Proposal (add event to Column directly from XAML):
private void DataGridTemplateColumn_PreparingCellForEdit(DataGridTemplateColumn sender, DataGridColumnPreparingCellForEditEventArgs e)
{
if (e.EditingElement is CalendarDatePicker calendar)
{
calendar.IsCalendarOpen = true;
}
}Thoughts, concerns @RBrid?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status