- 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:
Regis Brid 2019-10-15 13:56:13 -07:00
Родитель 7f3b4c12d1
Коммит 424118be2d
3 изменённых файлов: 53 добавлений и 18 удалений

Просмотреть файл

@ -5740,20 +5740,25 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
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,
// and it could have a parent even if the VisualTreeHelper doesn't find it.
DependencyObject parent = VisualTreeHelper.GetParent(focusedDependencyObject);
if (parent == null)
DependencyObject parent = null;
FrameworkElement element = focusedDependencyObject as FrameworkElement;
if (element == null)
{
FrameworkElement element = focusedDependencyObject as FrameworkElement;
if (element != null)
parent = VisualTreeHelper.GetParent(focusedDependencyObject);
}
else
{
parent = element.Parent;
if (parent == null)
{
parent = element.Parent;
if (parent != null)
{
dataGridWillReceiveRoutedEvent = false;
}
parent = VisualTreeHelper.GetParent(focusedDependencyObject);
}
else
{
dataGridWillReceiveRoutedEvent = false;
}
}

Просмотреть файл

@ -355,16 +355,29 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
{
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;
}
else if (comboBox != null)
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);
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)