From 260b0183fb9d402bde82f51522bf4979845490cc Mon Sep 17 00:00:00 2001 From: Roman Korneev Date: Fri, 3 Nov 2017 18:06:09 +0300 Subject: [PATCH] 1. Add FilterBox for CheckComboBox and CheckListBox controls. 2. New AllowFilter dependency property for both controls. --- .../CheckLists/Views/CheckListsView.xaml | 20 +- .../CheckLists/Views/CheckListsView.xaml.cs | 29 +- .../Implementation/CheckComboBox.cs | 63 +++- .../Themes/Aero2.NormalColor.xaml | 35 +- .../CheckComboBox/Themes/Generic.xaml | 17 +- .../Implementation/CheckListBox.cs | 60 ++++ .../Themes/Aero2.NormalColor.xaml | 17 +- .../CheckListBox/Themes/Generic.xaml | 13 +- .../FilterBox/Images/icon-search.png | Bin 0 -> 436 bytes .../FilterBox/Implementation/FilterBox.cs | 299 ++++++++++++++++++ .../FilterBox/Themes/Aero2.NormalColor.xaml | 120 +++++++ .../FilterBox/Themes/Genreric.xaml | 120 +++++++ .../Xceed.Wpf.Toolkit.csproj | 12 + 13 files changed, 762 insertions(+), 43 deletions(-) create mode 100644 ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Images/icon-search.png create mode 100644 ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Implementation/FilterBox.cs create mode 100644 ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Themes/Aero2.NormalColor.xaml create mode 100644 ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Themes/Genreric.xaml diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml index 038fd94c1..0f4034c64 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml @@ -49,6 +49,7 @@ + @@ -99,6 +100,16 @@ IsEnabled="False" Text="IsSelected" /> + + + @@ -151,8 +162,7 @@ - + @@ -171,11 +181,11 @@ Grid.Row="1" Margin="5" VerticalAlignment="Stretch" - ItemsSource="{Binding}" Delimiter="{Binding ElementName=_delimiter, Path=Text}" ValueMemberPath="{Binding ElementName=_valueMemberPath, Path=SelectedItem}" SelectedMemberPath="{Binding ElementName=_selectedMemberPath, Path=Text}" - DisplayMemberPath="{Binding ElementName=_displayMemberPath, Path=SelectedItem}" /> + DisplayMemberPath="{Binding ElementName=_displayMemberPath, Path=SelectedItem}" + AllowFilter="{Binding ElementName=_isAllowFilter, Path=IsChecked}" /> diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml.cs index e5a3beca2..9cdb708f6 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/Samples/CheckLists/Views/CheckListsView.xaml.cs @@ -15,7 +15,6 @@ This program is provided to you under the terms of the Microsoft Public *************************************************************************************/ using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; namespace Xceed.Wpf.Toolkit.LiveExplorer.Samples.CheckLists.Views @@ -28,20 +27,26 @@ public partial class CheckListsView : DemoView public CheckListsView() { InitializeComponent(); - this.DataContext = new List() + _itemModels.ItemsSource = GetData(); + _checkListBox.ItemsSource = GetData(); + _checkComboBox.ItemsSource = GetData(); + } + + private static List GetData() + { + return new List { - new Person(){ID=101, FirstName="John", LastName="Smith"}, - new Person(){ID=102, FirstName="Janel", LastName="Leverling"}, - new Person(){ID=103, FirstName="Laura", LastName="Callahan"}, - new Person(){ID=104, FirstName="Robert", LastName="King"}, - new Person(){ID=105, FirstName="Margaret", LastName="Peacock"}, - new Person(){ID=106, FirstName="Andrew", LastName="Fuller"}, - new Person(){ID=107, FirstName="Anne", LastName="Dodsworth"}, - new Person(){ID=108, FirstName="Nancy", LastName="Davolio"}, - new Person(){ID=109, FirstName="Naomi", LastName="Suyama"}, + new Person {ID=101, FirstName="John", LastName="Smith"}, + new Person {ID=102, FirstName="Janel", LastName="Leverling"}, + new Person {ID=103, FirstName="Laura", LastName="Callahan"}, + new Person {ID=104, FirstName="Robert", LastName="King"}, + new Person {ID=105, FirstName="Margaret", LastName="Peacock"}, + new Person {ID=106, FirstName="Andrew", LastName="Fuller"}, + new Person {ID=107, FirstName="Anne", LastName="Dodsworth"}, + new Person {ID=108, FirstName="Nancy", LastName="Davolio"}, + new Person {ID=109, FirstName="Naomi", LastName="Suyama"}, }; } - } public class Person : INotifyPropertyChanged diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Implementation/CheckComboBox.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Implementation/CheckComboBox.cs index 442471ad3..c2952264e 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Implementation/CheckComboBox.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Implementation/CheckComboBox.cs @@ -5,7 +5,7 @@ Extended WPF Toolkit Copyright (C) 2007-2013 Xceed Software Inc. This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license + License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license For more features, controls, and fast professional support, pick up the Plus Edition at http://xceed.com/wpf_toolkit @@ -18,26 +18,28 @@ This program is provided to you under the terms of the Microsoft Public using System.Linq; using System.Windows; using System.Windows.Input; -using Xceed.Wpf.Toolkit.Primitives; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Windows.Controls; -using System.Collections; using System.Collections.Generic; using System.Windows.Controls.Primitives; +using Xceed.Wpf.Toolkit.Core.Utilities; namespace Xceed.Wpf.Toolkit { + [TemplatePart( Name = PART_Popup, Type = typeof( Popup ) )] + [TemplatePart(Name = PART_FilterBox, Type = typeof(FilterBox))] public class CheckComboBox : Xceed.Wpf.Toolkit.Primitives.Selector { private const string PART_Popup = "PART_Popup"; + private const string PART_FilterBox = "PART_FilterBox"; #region Members - private ValueChangeHelper _displayMemberPathValuesChangeHelper; + private readonly ValueChangeHelper _displayMemberPathValuesChangeHelper; private bool _ignoreTextValueChanged; private Popup _popup; - private List _initialValue = new List(); + private FilterBox _filterBox; + private readonly List _initialValue = new List(); + private bool _allowFilter; #endregion @@ -179,6 +181,48 @@ protected virtual void OnMaxDropDownHeightChanged( double oldValue, double newVa #endregion + #region AllowFilter + public static readonly DependencyProperty AllowFilterProperty = DependencyProperty.Register( + "AllowFilter", + typeof(bool), + typeof(CheckComboBox), + new UIPropertyMetadata(true, AllowFilterChanged)); + + private static void AllowFilterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var selector = d as CheckComboBox; + if (selector != null) + selector.AllowFilterChanged((bool) e.NewValue); + } + + protected void AllowFilterChanged(bool value) + { + _allowFilter = value; + if (_filterBox != null) + { + SetFilter(value); + } + } + + public bool AllowFilter + { + get + { + return (bool)GetValue(AllowFilterProperty); + } + set + { + SetValue(AllowFilterProperty, value); + } + } + + private void SetFilter(bool value) + { + _filterBox.Clear(false); + _filterBox.Visibility = value ? Visibility.Visible : Visibility.Collapsed; + } + #endregion //AllowFilter + #endregion //Properties #region Base Class Overrides @@ -212,6 +256,9 @@ public override void OnApplyTemplate() if( _popup != null ) _popup.Opened += Popup_Opened; + + _filterBox = GetTemplateChild( PART_FilterBox ) as FilterBox; + SetFilter(_allowFilter); } #endregion //Base Class Overrides @@ -273,7 +320,7 @@ private void Popup_Opened( object sender, EventArgs e ) protected virtual void UpdateText() { #if VS2008 - string newValue = String.Join( Delimiter, SelectedItems.Cast().Select( x => GetItemDisplayValue( x ).ToString() ).ToArray() ); + string newValue = String.Join( Delimiter, SelectedItems.Cast().Select( x => GetItemDisplayValue( x ).ToString() ).ToArray() ); #else string newValue = String.Join( Delimiter, SelectedItems.Cast().Select( x => GetItemDisplayValue( x ) ) ); #endif diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Aero2.NormalColor.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Aero2.NormalColor.xaml index 4638e003f..72e517f06 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Aero2.NormalColor.xaml +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Aero2.NormalColor.xaml @@ -21,6 +21,10 @@ xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes" xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes"> + + + + M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z @@ -50,8 +54,9 @@ - + - + @@ -165,18 +171,25 @@ Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}" /> - + + + + - + - + \ No newline at end of file diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Generic.xaml index d957d50db..4a538dab9 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckComboBox/Themes/Generic.xaml @@ -20,6 +20,10 @@ xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters" xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes"> + + + + - + + + + diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Implementation/CheckListBox.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Implementation/CheckListBox.cs index 3796b06da..7789c13a6 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Implementation/CheckListBox.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Implementation/CheckListBox.cs @@ -19,8 +19,60 @@ This program is provided to you under the terms of the Microsoft Public namespace Xceed.Wpf.Toolkit { + [TemplatePart(Name = PART_FilterBox, Type = typeof(FilterBox))] public class CheckListBox : Selector { + private const string PART_FilterBox = "PART_FilterBox"; + + #region Members + + private FilterBox _filterBox; + private bool _allowFilter; + + #endregion + + #region AllowFilter + public static readonly DependencyProperty AllowFilterProperty = DependencyProperty.Register( + "AllowFilter", + typeof(bool), + typeof(CheckListBox), + new UIPropertyMetadata(true, AllowFilterChanged)); + + private static void AllowFilterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var selector = d as CheckListBox; + if (selector != null) + selector.AllowFilterChanged((bool)e.NewValue); + } + + protected void AllowFilterChanged(bool value) + { + _allowFilter = value; + if (_filterBox != null) + { + SetFilter(value); + } + } + + public bool AllowFilter + { + get + { + return (bool)GetValue(AllowFilterProperty); + } + set + { + SetValue(AllowFilterProperty, value); + } + } + + private void SetFilter(bool value) + { + _filterBox.Clear(false); + _filterBox.Visibility = value ? Visibility.Visible : Visibility.Collapsed; + } + #endregion //AllowFilter + #region Constructors static CheckListBox() @@ -34,5 +86,13 @@ public CheckListBox() } #endregion //Constructors + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _filterBox = GetTemplateChild(PART_FilterBox) as FilterBox; + SetFilter(_allowFilter); + } } } diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Themes/Aero2.NormalColor.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Themes/Aero2.NormalColor.xaml index 082b2d6c2..2f9bd2808 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Themes/Aero2.NormalColor.xaml +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CheckListBox/Themes/Aero2.NormalColor.xaml @@ -19,8 +19,12 @@ xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes" xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"> - + + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Themes/Genreric.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Themes/Genreric.xaml new file mode 100644 index 000000000..740bf3f88 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/FilterBox/Themes/Genreric.xaml @@ -0,0 +1,120 @@ + + + + + + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj index 924509db3..daafcdc47 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj @@ -62,6 +62,14 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -391,6 +399,7 @@ + @@ -780,6 +789,9 @@ + + +