@ -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 . IsCheck edProperty , isCheckedBinding ) ;
checkListBoxItem . SetBinding ( CheckListBoxItem . IsSelect edProperty , isCheckedBinding ) ;
}
base . PrepareContainerForItemOverride ( element , item ) ;
_ surpressSelectionChanged = false ;
}
protected override void OnSelectionChanged ( SelectionChangedEventArgs e )
{
if ( ! _ surpressSelectionChanged )
base . OnSelectionChanged ( e ) ;
}
#endregion //Base Class Overrides