Skip to content

Commit

Permalink
Fix MultipleChoiceFilter: concurrent filter may lock out each other
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Aug 28, 2021
1 parent f4de153 commit 326a648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/DataGridExtensions/DataGridFilterColumnControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public object? Filter
/// You may need to include "NotifyOnTargetUpdated=true" in the binding of the DataGrid.ItemsSource to get up-to-date
/// values when the source object changes.
/// </remarks>
public IEnumerable<string> Values => InternalValues().Distinct().ToList().AsReadOnly();
public IReadOnlyCollection<string> Values => InternalValues().Distinct().ToList().AsReadOnly();

/// <summary>
/// Returns all distinct source values of this column as string.
Expand All @@ -186,7 +186,7 @@ public object? Filter
/// You may need to include "NotifyOnTargetUpdated=true" in the binding of the DataGrid.ItemsSource to get up-to-date
/// values when the source object changes.
/// </remarks>
public IEnumerable<string> SourceValues
public IReadOnlyCollection<string> SourceValues
{
get
{
Expand All @@ -205,7 +205,7 @@ public IEnumerable<string> SourceValues
/// You may need to include "NotifyOnTargetUpdated=true" in the binding of the DataGrid.ItemsSource to get up-to-date
/// values when the source object changes.
/// </remarks>
public IEnumerable<string> SelectableValues
public IReadOnlyCollection<string> SelectableValues
{
get
{
Expand Down
10 changes: 5 additions & 5 deletions src/DataGridExtensions/MultipleChoiceFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public bool HasTextFilter
public static readonly DependencyProperty HasTextFilterProperty = DependencyProperty.Register(
"HasTextFilter", typeof(bool), typeof(MultipleChoiceFilter), new PropertyMetadata(default(bool)));

private IEnumerable<string?>? SourceValues => (IEnumerable<string?>?)GetValue(SourceValuesProperty);
private IReadOnlyCollection<string?>? SourceValues => (IReadOnlyCollection<string?>?)GetValue(SourceValuesProperty);

private static readonly DependencyProperty SourceValuesProperty =
DependencyProperty.Register("SourceValues", typeof(IList<string>), typeof(MultipleChoiceFilter), new FrameworkPropertyMetadata(null, (sender, e) => ((MultipleChoiceFilter)sender).SourceValues_Changed((IList<string>)e.NewValue)));
DependencyProperty.Register("SourceValues", typeof(IReadOnlyCollection<string>), typeof(MultipleChoiceFilter), new FrameworkPropertyMetadata(null, (sender, e) => ((MultipleChoiceFilter)sender).SourceValues_Changed((IReadOnlyCollection<string>)e.NewValue)));

private void SourceValues_Changed(IEnumerable<string?>? newValue)
private void SourceValues_Changed(IReadOnlyCollection<string?>? newValue)
{
OnSourceValuesChanged(newValue);
}
Expand Down Expand Up @@ -197,12 +197,12 @@ protected virtual MultipleChoiceContentFilter CreateFilter(IEnumerable<string?>?
/// Called when the source values have changed.
/// </summary>
/// <param name="newValue">The new value.</param>
protected virtual void OnSourceValuesChanged(IEnumerable<string?>? newValue)
protected virtual void OnSourceValuesChanged(IReadOnlyCollection<string?>? newValue)
{
var values = Values;
var filterRegex = Filter?.Regex;

if (newValue == null)
if (newValue == null || !newValue.Any())
{
values.Clear();
}
Expand Down

0 comments on commit 326a648

Please sign in to comment.