diff --git a/src/DataGridExtensions/DataGridFilterColumnControl.cs b/src/DataGridExtensions/DataGridFilterColumnControl.cs index 8161167..548651f 100644 --- a/src/DataGridExtensions/DataGridFilterColumnControl.cs +++ b/src/DataGridExtensions/DataGridFilterColumnControl.cs @@ -15,6 +15,8 @@ using DataGridExtensions.Framework; using Throttle; + using TomsToolbox.Wpf.Converters; + using BooleanToVisibilityConverter = TomsToolbox.Wpf.Converters.BooleanToVisibilityConverter; /// /// This class is the control hosting all information needed for filtering of one column. @@ -24,7 +26,6 @@ /// public class DataGridFilterColumnControl : Control, INotifyPropertyChanged { - private static readonly BooleanToVisibilityConverter _booleanToVisibilityConverter = new BooleanToVisibilityConverter(); private static readonly ControlTemplate _emptyControlTemplate = new ControlTemplate(); private bool _getCellContentMustUseBinding; @@ -74,7 +75,23 @@ private void Self_Loaded(object sender, RoutedEventArgs e) // Bind our IsFilterVisible and Template properties to the corresponding properties attached to the // DataGridColumnHeader.Column property. Use binding instead of simple assignment since columnHeader.Column is still null at this point. var isFilterVisiblePropertyPath = new PropertyPath("(0)", DataGridFilterColumn.IsFilterVisibleProperty); - BindingOperations.SetBinding(this, VisibilityProperty, new Binding() { Path = isFilterVisiblePropertyPath, Source = column, Mode = BindingMode.OneWay, Converter = _booleanToVisibilityConverter }); + var isAutoFilterEnabledPropertyPath = new PropertyPath("(0)", DataGridFilter.IsAutoFilterEnabledProperty); + + BindingOperations.SetBinding(this, VisibilityProperty, new MultiBinding() + { + Converter = new CompositeMultiValueConverter() + { + MultiValueConverter = LogicalMultiValueConverter.And, + Converters = { + TomsToolbox.Wpf.Converters.BooleanToVisibilityConverter.Default + } + }, + Bindings = + { + new Binding() { Path = isFilterVisiblePropertyPath, Source = column, Mode = BindingMode.OneWay }, + new Binding() { Path = isAutoFilterEnabledPropertyPath, Source = DataGrid, Mode = BindingMode.OneWay } + } + }); ; var templatePropertyPath = new PropertyPath("(0)", DataGridFilterColumn.TemplateProperty); BindingOperations.SetBinding(this, TemplateProperty, new Binding() { Path = templatePropertyPath, Source = column, Mode = BindingMode.OneWay }); diff --git a/src/DataGridExtensions/DataGridFilterHost.cs b/src/DataGridExtensions/DataGridFilterHost.cs index 8ae0162..e9e1fd3 100644 --- a/src/DataGridExtensions/DataGridFilterHost.cs +++ b/src/DataGridExtensions/DataGridFilterHost.cs @@ -100,14 +100,14 @@ internal void Enable(bool value) { _isFilteringEnabled = value; - var visibility = value ? Visibility.Visible : Visibility.Hidden; - - foreach (var control in FilterColumnControls) + if (!value) { - control.Visibility = visibility; + Clear(); + } + else + { + EvaluateFilter(); } - - EvaluateFilter(); } /// diff --git a/src/DataGridExtensionsSample/Views/BasicView.xaml.cs b/src/DataGridExtensionsSample/Views/BasicView.xaml.cs index 1deaa76..4f7aa4a 100644 --- a/src/DataGridExtensionsSample/Views/BasicView.xaml.cs +++ b/src/DataGridExtensionsSample/Views/BasicView.xaml.cs @@ -24,6 +24,7 @@ public BasicView() // Sample to manipulate the filter values by code. DataGrid.Columns[0].SetFilter("True"); DataGrid.Columns[2].SetFilter("3"); + DataGrid.Columns[3].SetIsFilterVisible(false); })); // Sample usage of the filtering event