DataGrid fixes for:
- Issue #2977 - Current cell not restored after row deletion, causing crash - Crash when undoing combobox column change - Inability to click combobox text to open dropdown
This commit is contained in:
Родитель
7f3b4c12d1
Коммит
424118be2d
|
@ -5740,20 +5740,25 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk up the visual tree. If we hit the root, try using the framework element's
|
// Walk up the visual tree. Try using the framework element's
|
||||||
// parent. We do this because Popups behave differently with respect to the visual tree,
|
// parent. We do this because Popups behave differently with respect to the visual tree,
|
||||||
// and it could have a parent even if the VisualTreeHelper doesn't find it.
|
// and it could have a parent even if the VisualTreeHelper doesn't find it.
|
||||||
DependencyObject parent = VisualTreeHelper.GetParent(focusedDependencyObject);
|
DependencyObject parent = null;
|
||||||
if (parent == null)
|
FrameworkElement element = focusedDependencyObject as FrameworkElement;
|
||||||
|
if (element == null)
|
||||||
{
|
{
|
||||||
FrameworkElement element = focusedDependencyObject as FrameworkElement;
|
parent = VisualTreeHelper.GetParent(focusedDependencyObject);
|
||||||
if (element != null)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parent = element.Parent;
|
||||||
|
if (parent == null)
|
||||||
{
|
{
|
||||||
parent = element.Parent;
|
parent = VisualTreeHelper.GetParent(focusedDependencyObject);
|
||||||
if (parent != null)
|
}
|
||||||
{
|
else
|
||||||
dataGridWillReceiveRoutedEvent = false;
|
{
|
||||||
}
|
dataGridWillReceiveRoutedEvent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,16 +355,29 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
|
protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
|
||||||
{
|
{
|
||||||
var comboBox = editingElement as ComboBox;
|
var comboBox = editingElement as ComboBox;
|
||||||
if (comboBox != null && uneditedValue != null)
|
|
||||||
{
|
|
||||||
var value = uneditedValue.GetType().GetProperty(Binding.Path.Path).GetValue(uneditedValue);
|
|
||||||
var selection = ItemsSource?.Cast<object>().FirstOrDefault(x => x.GetType().GetProperty(Binding.Path.Path).GetValue(x).Equals(value));
|
|
||||||
|
|
||||||
comboBox.SelectedItem = selection;
|
if (comboBox != null)
|
||||||
}
|
|
||||||
else if (comboBox != null)
|
|
||||||
{
|
{
|
||||||
comboBox.SelectedItem = null;
|
if (uneditedValue != null)
|
||||||
|
{
|
||||||
|
var property = uneditedValue.GetType().GetProperty(Binding.Path.Path);
|
||||||
|
|
||||||
|
if (property == null)
|
||||||
|
{
|
||||||
|
comboBox.SelectedItem = uneditedValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var value = property.GetValue(uneditedValue);
|
||||||
|
var selection = ItemsSource?.Cast<object>().FirstOrDefault(x => x.GetType().GetProperty(Binding.Path.Path).GetValue(x).Equals(value));
|
||||||
|
|
||||||
|
comboBox.SelectedItem = selection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
comboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2706,6 +2706,23 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
CorrectSlotsAfterDeletion(slot, isRow);
|
CorrectSlotsAfterDeletion(slot, isRow);
|
||||||
|
|
||||||
OnRemovedElement(slot, item, isRow);
|
OnRemovedElement(slot, item, isRow);
|
||||||
|
|
||||||
|
// Synchronize CurrentCellCoordinates, CurrentColumn, CurrentColumnIndex, CurrentItem
|
||||||
|
// and CurrentSlot with the currently edited cell, since OnRemovingElement called
|
||||||
|
// SetCurrentCellCore(-1, -1) to temporarily reset the current cell.
|
||||||
|
if (_temporarilyResetCurrentCell &&
|
||||||
|
_editingColumnIndex != -1 &&
|
||||||
|
_previousCurrentItem != null &&
|
||||||
|
this.EditingRow != null &&
|
||||||
|
this.EditingRow.Slot != -1)
|
||||||
|
{
|
||||||
|
ProcessSelectionAndCurrency(
|
||||||
|
columnIndex: _editingColumnIndex,
|
||||||
|
item: _previousCurrentItem,
|
||||||
|
backupSlot: this.EditingRow.Slot,
|
||||||
|
action: DataGridSelectionAction.None,
|
||||||
|
scrollIntoView: false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveNonDisplayedRows(int newFirstDisplayedSlot, int newLastDisplayedSlot)
|
private void RemoveNonDisplayedRows(int newFirstDisplayedSlot, int newLastDisplayedSlot)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче