Browse Source

CheckListBox: still working on it

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
171f315dda
  1. 64
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBox.cs
  2. 67
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxItem.cs
  3. 10
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Themes/Generic.xaml

64
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBox.cs

@ -19,11 +19,18 @@ namespace Microsoft.Windows.Controls
{
public class CheckListBox : MultiSelector
{
private bool _surpressSelectionChanged;
static CheckListBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckListBox), new FrameworkPropertyMetadata(typeof(CheckListBox)));
}
public CheckListBox()
{
}
#region Properties
public static readonly DependencyProperty CheckedMemberPathProperty = DependencyProperty.Register("CheckedMemberPath", typeof(string), typeof(CheckListBox), new UIPropertyMetadata(null));
@ -41,49 +48,6 @@ namespace Microsoft.Windows.Controls
set { SetValue(CommandProperty, value); }
}
//public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CheckListBox), new UIPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged), new CoerceValueCallback(OnCoerceItemsSource)));
//private static object OnCoerceItemsSource(DependencyObject o, object value)
//{
// CheckListBox checkListBox = o as CheckListBox;
// if (checkListBox != null)
// return checkListBox.OnCoerceItemsSource((IEnumerable)value);
// else
// return value;
//}
//private static void OnItemsSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
//{
// CheckListBox checkListBox = o as CheckListBox;
// if (checkListBox != null)
// checkListBox.OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
//}
//protected virtual IEnumerable OnCoerceItemsSource(IEnumerable value)
//{
// // TODO: Keep the proposed value within the desired range.
// return value;
//}
//protected virtual void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
//{
// // TODO: Add your property changed side-effects. Descendants can override as well.
//}
//public IEnumerable ItemsSource
//{
// // IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!
// get
// {
// return (IEnumerable)GetValue(ItemsSourceProperty);
// }
// set
// {
// SetValue(ItemsSourceProperty, value);
// }
//}
#endregion //Properties
#region Base Class Overrides
@ -100,16 +64,24 @@ namespace Microsoft.Windows.Controls
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
var checkListBoxItem = element as FrameworkElement;
_surpressSelectionChanged = true;
var checkListBoxItem = element as FrameworkElement;
if (!String.IsNullOrEmpty(CheckedMemberPath))
{
Binding isCheckedBinding = new Binding(CheckedMemberPath);
isCheckedBinding.Source = item;
checkListBoxItem.SetBinding(CheckListBoxItem.IsCheckedProperty, isCheckedBinding);
checkListBoxItem.SetBinding(CheckListBoxItem.IsSelectedProperty, isCheckedBinding);
}
base.PrepareContainerForItemOverride(element, item);
_surpressSelectionChanged = false;
}
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
if (!_surpressSelectionChanged)
base.OnSelectionChanged(e);
}
#endregion //Base Class Overrides

67
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxItem.cs

@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
namespace Microsoft.Windows.Controls
{
@ -21,11 +22,67 @@ namespace Microsoft.Windows.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckListBoxItem), new FrameworkPropertyMetadata(typeof(CheckListBoxItem)));
}
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(CheckListBoxItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public bool IsChecked
#region Properties
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(CheckListBoxItem), new UIPropertyMetadata(false, OnIsSelectedChanged));
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
private static void OnIsSelectedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
CheckListBoxItem checkListBoxItem = o as CheckListBoxItem;
if (checkListBoxItem != null)
checkListBoxItem.OnIsSelectedChanged((bool)e.OldValue, (bool)e.NewValue);
}
protected virtual void OnIsSelectedChanged(bool oldValue, bool newValue)
{
if (newValue)
OnSelected(new RoutedEventArgs(Selector.SelectedEvent, this));
else
OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, this));
}
#endregion //Properties
#region Events
public static readonly RoutedEvent SelectedEvent = Selector.SelectedEvent.AddOwner(typeof(CheckListBoxItem));
public event RoutedEventHandler Selected
{
add { base.AddHandler(SelectedEvent, value); }
remove { base.RemoveHandler(SelectedEvent, value); }
}
public static readonly RoutedEvent UnselectedEvent = Selector.UnselectedEvent.AddOwner(typeof(CheckListBoxItem));
public event RoutedEventHandler Unselected
{
add { base.AddHandler(UnselectedEvent, value); }
remove { base.RemoveHandler(UnselectedEvent, value); }
}
#endregion
#region Methods
protected virtual void OnSelected(RoutedEventArgs e)
{
this.OnIsSelectedChanged(true, e);
}
protected virtual void OnUnselected(RoutedEventArgs e)
{
get { return (bool)GetValue(IsCheckedProperty); }
set { SetValue(IsCheckedProperty, value); }
}
this.OnIsSelectedChanged(false, e);
}
private void OnIsSelectedChanged(bool newValue, RoutedEventArgs e)
{
base.RaiseEvent(e);
}
#endregion //Methods
}
}

10
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Themes/Generic.xaml

@ -34,7 +34,7 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox Name="PART_CheckBox" IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
<CheckBox Name="PART_CheckBox" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
Command="{Binding Command, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CheckListBox}}"
CommandParameter="{Binding}" VerticalAlignment="Center" Focusable="False" Margin="1,1,5,1"/>
<Border Grid.Column="1">
@ -43,16 +43,16 @@
</Grid>
</Border>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsChecked" Value="true">
<!--<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="_background" Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>-->
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="_background" Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate.Triggers>-->
</ControlTemplate>
</Setter.Value>
</Setter>

Loading…
Cancel
Save