Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter box for CheckComboBox and CheckListBox controls #1221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -99,6 +100,16 @@
IsEnabled="False"
Text="IsSelected" />

<TextBlock Grid.Row="4" Grid.Column="0"
Text="AllowFilter:"
Margin="2,5,5,5"/>
<CheckBox x:Name="_isAllowFilter"
Grid.Row="4" Grid.Column="1"
Margin="5"
HorizontalAlignment="Left"
ClickMode="Press"
IsChecked="False" />

<TextBlock Grid.Row="0" Grid.Column="2"
Text="DisplayMemberPath:"
Margin="5"/>
Expand Down Expand Up @@ -151,8 +162,7 @@
</GroupBox>

<GroupBox Header="Item Models" Grid.Row="1" Margin="5">
<ListBox DisplayMemberPath="ModelDisplay" FontFamily="Global Monospace"
ItemsSource="{Binding}"/>
<ListBox x:Name="_itemModels" DisplayMemberPath="ModelDisplay" FontFamily="Global Monospace"/>
</GroupBox>

<Grid Grid.Row="2">
Expand All @@ -171,23 +181,23 @@
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}" />

<TextBlock Text="CheckComboBox Usage:" Grid.Column="1" Margin="5" Style="{StaticResource Header}"/>
<xctk:CheckComboBox Grid.Column="1"
x:Name="_checkComboBox"
Grid.Row="1"
Margin="5"
VerticalAlignment="Top"
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}"
AllowFilter="{Binding ElementName=_isAllowFilter, Path=IsChecked}"
IsEditable="False"
IsDropDownOpen="false"
MaxDropDownHeight="100"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*************************************************************************************/

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace Xceed.Wpf.Toolkit.LiveExplorer.Samples.CheckLists.Views
Expand All @@ -28,20 +27,26 @@ public partial class CheckListsView : DemoView
public CheckListsView()
{
InitializeComponent();
this.DataContext = new List<Person>()
_itemModels.ItemsSource = GetData();
_checkListBox.ItemsSource = GetData();
_checkComboBox.ItemsSource = GetData();
}

private static List<Person> GetData()
{
return new List<Person>
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -18,26 +18,28 @@
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<object> _initialValue = new List<object>();
private FilterBox _filterBox;
private readonly List<object> _initialValue = new List<object>();
private bool _allowFilter;

#endregion

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<object>().Select( x => GetItemDisplayValue( x ).ToString() ).ToArray() );
string newValue = String.Join( Delimiter, SelectedItems.Cast<object>().Select( x => GetItemDisplayValue( x ).ToString() ).ToArray() );
#else
string newValue = String.Join( Delimiter, SelectedItems.Cast<object>().Select( x => GetItemDisplayValue( x ) ) );
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes"
xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../FilterBox/Themes/Aero2.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>

<conv:InverseBoolConverter x:Key="InverseBoolConverter" />

<Geometry x:Key="DownArrowGeometry">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</Geometry>
Expand Down Expand Up @@ -50,8 +54,9 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
Width="0" />
<ColumnDefinition
MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
Width="0" />
</Grid.ColumnDefinitions>

<TextBox x:Name="TextBox"
Expand Down Expand Up @@ -93,8 +98,9 @@
TargetName="Arrow"
Value="#AFAFAF" />
</Trigger>
<DataTrigger Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type local:CheckComboBox}}}"
Value="True">
<DataTrigger
Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type local:CheckComboBox}}}"
Value="True">
<Setter Property="IsReadOnly"
Value="False"
TargetName="TextBox" />
Expand Down Expand Up @@ -165,18 +171,25 @@
Height="{Binding ActualHeight, ElementName=DropDownBorder}"
Width="{Binding ActualWidth, ElementName=DropDownBorder}" />
</Canvas>
<ItemsPresenter x:Name="PART_ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<DockPanel>
<local:FilterBox x:Name="PART_FilterBox"
DockPanel.Dock="Top"
Header="Type here to filter"
TargetControl="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}"
FilterTextBindingPath="{TemplateBinding DisplayMemberPath}" />
<ItemsPresenter x:Name="PART_ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</DockPanel>
</Grid>
</ScrollViewer>
</Border>
</Grid>
</Popup>

<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<ToggleButton x:Name="PART_DropDownButton"
Content="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
BorderBrush="{TemplateBinding BorderBrush}"
Expand Down Expand Up @@ -206,4 +219,4 @@
</Style.Triggers>
</Style>

</ResourceDictionary>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters"
xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../FilterBox/Themes/Genreric.xaml" />
</ResourceDictionary.MergedDictionaries>

<conv:InverseBoolConverter x:Key="InverseBoolConverter" />

<SolidColorBrush x:Key="ButtonNormalBorder"
Expand Down Expand Up @@ -167,9 +171,16 @@
Height="{Binding ActualHeight, ElementName=DropDownBorder}"
Width="{Binding ActualWidth, ElementName=DropDownBorder}" />
</Canvas>
<ItemsPresenter x:Name="PART_ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<DockPanel>
<local:FilterBox x:Name="PART_FilterBox"
DockPanel.Dock="Top"
Header="Type here to filter"
TargetControl="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}"
FilterTextBindingPath="{TemplateBinding DisplayMemberPath}" />
<ItemsPresenter x:Name="PART_ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</DockPanel>
</Grid>
</ScrollViewer>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,60 @@

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()
Expand All @@ -34,5 +86,13 @@ public CheckListBox()
}

#endregion //Constructors

public override void OnApplyTemplate()
{
base.OnApplyTemplate();

_filterBox = GetTemplateChild(PART_FilterBox) as FilterBox;
SetFilter(_allowFilter);
}
}
}