Skip to content

Commit

Permalink
Merge remote-tracking branch 'tmijail/ItemsSource-bug-fix' (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
vain0x committed Apr 22, 2023
2 parents e1747a7 + 90fa51f commit 2994497
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ string TextFromItem(object item)

private static void ItemsSourcePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dpcea)
{
var comboBox = (ComboBox)dependencyObject;
var previousSelectedItem = comboBox.SelectedItem;

if (dpcea.NewValue is ICollectionView cv)
{
((AutoCompleteComboBox)dependencyObject).defaultItemsFilter = cv.Filter;
((ComboBox)dependencyObject).ItemsSource = cv;
comboBox.ItemsSource = cv;
}
else
{
Expand All @@ -83,7 +86,15 @@ private static void ItemsSourcePropertyChanged(DependencyObject dependencyObject
{
Source = newValue
};
((ComboBox)dependencyObject).ItemsSource = newCollectionViewSource.View;
comboBox.ItemsSource = newCollectionViewSource.View;
}

comboBox.SelectedItem = previousSelectedItem;

// if ItemsSource doesn't contain previousSelectedItem
if (comboBox.SelectedItem != previousSelectedItem)
{
comboBox.SelectedItem = null;
}
}
#endregion ItemsSource
Expand Down

0 comments on commit 2994497

Please sign in to comment.