Browse Source

CheckListBox: renamed properties

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
f12df52f69
  1. 60
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBox.cs
  2. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxCheckedChangedEventArgs.cs
  3. 18
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxItem.cs
  4. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxSelectionChangedEventArgs.cs
  5. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Themes/Generic.xaml
  6. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

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

@ -22,9 +22,9 @@ namespace Microsoft.Windows.Controls
public CheckListBox() public CheckListBox()
{ {
SelectedItems = new List<object>(); CheckedItems = new List<object>();
AddHandler(CheckListBox.SelectedEvent, new RoutedEventHandler(CheckListBox_Selected)); AddHandler(CheckListBox.CheckedEvent, new RoutedEventHandler(CheckListBox_Checked));
AddHandler(CheckListBox.UnselectedEvent, new RoutedEventHandler(CheckListBox_Unselected)); AddHandler(CheckListBox.UncheckedEvent, new RoutedEventHandler(CheckListBox_Unchecked));
} }
#endregion //Constructors #endregion //Constructors
@ -46,30 +46,30 @@ namespace Microsoft.Windows.Controls
set { SetValue(CommandProperty, value); } set { SetValue(CommandProperty, value); }
} }
#region SelectedItem #region CheckedItem
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(object), typeof(CheckListBox), new UIPropertyMetadata(null, OnSelectedItemChanged)); public static readonly DependencyProperty CheckedItemProperty = DependencyProperty.Register("CheckedItem", typeof(object), typeof(CheckListBox), new UIPropertyMetadata(null, OnCheckedItemChanged));
public object SelectedItem public object CheckedItem
{ {
get { return (object)GetValue(SelectedItemProperty); } get { return (object)GetValue(CheckedItemProperty); }
set { SetValue(SelectedItemProperty, value); } set { SetValue(CheckedItemProperty, value); }
} }
private static void OnSelectedItemChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) private static void OnCheckedItemChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{ {
CheckListBox checkListBox = o as CheckListBox; CheckListBox checkListBox = o as CheckListBox;
if (checkListBox != null) if (checkListBox != null)
checkListBox.OnSelectedItemChanged((object)e.OldValue, (object)e.NewValue); checkListBox.OnCheckedItemChanged((object)e.OldValue, (object)e.NewValue);
} }
protected virtual void OnSelectedItemChanged(object oldValue, object newValue) protected virtual void OnCheckedItemChanged(object oldValue, object newValue)
{ {
} }
#endregion //SelectedItem #endregion //CheckedItem
public IList SelectedItems { get; private set; } public IList CheckedItems { get; private set; }
#endregion //Properties #endregion //Properties
@ -94,7 +94,7 @@ namespace Microsoft.Windows.Controls
Binding isCheckedBinding = new Binding(CheckedMemberPath); Binding isCheckedBinding = new Binding(CheckedMemberPath);
isCheckedBinding.Mode = BindingMode.TwoWay; isCheckedBinding.Mode = BindingMode.TwoWay;
isCheckedBinding.Source = item; isCheckedBinding.Source = item;
checkListBoxItem.SetBinding(CheckListBoxItem.IsSelectedProperty, isCheckedBinding); checkListBoxItem.SetBinding(CheckListBoxItem.IsCheckedProperty, isCheckedBinding);
} }
base.PrepareContainerForItemOverride(element, item); base.PrepareContainerForItemOverride(element, item);
_surpressSelectionChanged = false; _surpressSelectionChanged = false;
@ -104,39 +104,39 @@ namespace Microsoft.Windows.Controls
#region Events #region Events
public static readonly RoutedEvent SelectedEvent = EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble, typeof(SelectionChangedEventHandler), typeof(CheckListBox)); public static readonly RoutedEvent CheckedEvent = EventManager.RegisterRoutedEvent("CheckedEvent", RoutingStrategy.Bubble, typeof(SelectionChangedEventHandler), typeof(CheckListBox));
public static readonly RoutedEvent UnselectedEvent = EventManager.RegisterRoutedEvent("Unselected", RoutingStrategy.Bubble, typeof(SelectionChangedEventHandler), typeof(CheckListBox)); public static readonly RoutedEvent UncheckedEvent = EventManager.RegisterRoutedEvent("UncheckedEvent", RoutingStrategy.Bubble, typeof(SelectionChangedEventHandler), typeof(CheckListBox));
public static readonly RoutedEvent SelectionChangedEvent = EventManager.RegisterRoutedEvent("SelectionChanged", RoutingStrategy.Bubble, typeof(CheckListBoxSelectionChangedEventHandler), typeof(CheckListBox)); public static readonly RoutedEvent CheckedChangedEvent = EventManager.RegisterRoutedEvent("CheckedChanged", RoutingStrategy.Bubble, typeof(CheckListBoxCheckedChangedEventHandler), typeof(CheckListBox));
public event CheckListBoxSelectionChangedEventHandler SelectionChanged public event CheckListBoxCheckedChangedEventHandler CheckedChanged
{ {
add { AddHandler(SelectionChangedEvent, value); } add { AddHandler(CheckedChangedEvent, value); }
remove { RemoveHandler(SelectionChangedEvent, value); } remove { RemoveHandler(CheckedChangedEvent, value); }
} }
#endregion //Events #endregion //Events
void CheckListBox_Selected(object sender, RoutedEventArgs e) void CheckListBox_Checked(object sender, RoutedEventArgs e)
{ {
SetSelectedItem(e.OriginalSource); SetCheckedItem(e.OriginalSource);
SelectedItems.Add(SelectedItem); CheckedItems.Add(CheckedItem);
OnCheckedChanged(); OnCheckedChanged();
} }
void CheckListBox_Unselected(object sender, RoutedEventArgs e) void CheckListBox_Unchecked(object sender, RoutedEventArgs e)
{ {
SetSelectedItem(e.OriginalSource); SetCheckedItem(e.OriginalSource);
SelectedItems.Remove(SelectedItem); CheckedItems.Remove(CheckedItem);
OnCheckedChanged(); OnCheckedChanged();
} }
private void SetSelectedItem(object source) private void SetCheckedItem(object source)
{ {
if (_surpressSelectionChanged) if (_surpressSelectionChanged)
return; return;
var selectedCheckListBoxItem = source as FrameworkElement; var selectedCheckListBoxItem = source as FrameworkElement;
if (selectedCheckListBoxItem != null) if (selectedCheckListBoxItem != null)
SelectedItem = selectedCheckListBoxItem.DataContext; CheckedItem = selectedCheckListBoxItem.DataContext;
} }
private void OnCheckedChanged() private void OnCheckedChanged()
@ -144,10 +144,10 @@ namespace Microsoft.Windows.Controls
if (_surpressSelectionChanged) if (_surpressSelectionChanged)
return; return;
RaiseEvent(new CheckListBoxSelectionChangedEventArgs(CheckListBox.SelectionChangedEvent, this, SelectedItem)); RaiseEvent(new CheckListBoxCheckedChangedEventArgs(CheckListBox.CheckedChangedEvent, this, CheckedItem));
if (Command != null) if (Command != null)
Command.Execute(SelectedItem); Command.Execute(CheckedItem);
} }
} }
} }

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxCheckedChangedEventArgs.cs

@ -0,0 +1,17 @@
using System;
using System.Windows;
namespace Microsoft.Windows.Controls
{
public delegate void CheckListBoxCheckedChangedEventHandler(object sender, CheckListBoxCheckedChangedEventArgs e);
public class CheckListBoxCheckedChangedEventArgs : RoutedEventArgs
{
public object Item { get; private set; }
public CheckListBoxCheckedChangedEventArgs(RoutedEvent routedEvent, object source, object item)
: base(routedEvent, source)
{
Item = item;
}
}
}

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

@ -29,11 +29,11 @@ namespace Microsoft.Windows.Controls
#region Properties #region Properties
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(CheckListBoxItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSelectedChanged)); public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(CheckListBoxItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSelectedChanged));
public bool IsSelected public bool IsChecked
{ {
get { return (bool)GetValue(IsSelectedProperty); } get { return (bool)GetValue(IsCheckedProperty); }
set { SetValue(IsSelectedProperty, value); } set { SetValue(IsCheckedProperty, value); }
} }
private static void OnIsSelectedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) private static void OnIsSelectedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
@ -46,17 +46,17 @@ namespace Microsoft.Windows.Controls
protected virtual void OnIsSelectedChanged(bool oldValue, bool newValue) protected virtual void OnIsSelectedChanged(bool oldValue, bool newValue)
{ {
if (newValue) if (newValue)
RaiseSelectionChangedEvent(new RoutedEventArgs(CheckListBox.SelectedEvent, this)); RaiseSelectionChangedEvent(new RoutedEventArgs(CheckListBox.CheckedEvent, this));
else else
RaiseSelectionChangedEvent(new RoutedEventArgs(CheckListBox.UnselectedEvent, this)); RaiseSelectionChangedEvent(new RoutedEventArgs(CheckListBox.UncheckedEvent, this));
} }
#endregion //Properties #endregion //Properties
#region Events #region Events
public static readonly RoutedEvent SelectedEvent = CheckListBox.SelectedEvent.AddOwner(typeof(CheckListBoxItem)); public static readonly RoutedEvent SelectedEvent = CheckListBox.CheckedEvent.AddOwner(typeof(CheckListBoxItem));
public static readonly RoutedEvent UnselectedEvent = CheckListBox.UnselectedEvent.AddOwner(typeof(CheckListBoxItem)); public static readonly RoutedEvent UnselectedEvent = CheckListBox.UncheckedEvent.AddOwner(typeof(CheckListBoxItem));
#endregion #endregion
@ -64,7 +64,7 @@ namespace Microsoft.Windows.Controls
void CheckListBoxItem_MouseDown(object sender, MouseButtonEventArgs e) void CheckListBoxItem_MouseDown(object sender, MouseButtonEventArgs e)
{ {
IsSelected = !IsSelected; IsChecked = !IsChecked;
} }
#endregion //Event Hanlders #endregion //Event Hanlders

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxSelectionChangedEventArgs.cs

@ -1,17 +0,0 @@
using System;
using System.Windows;
namespace Microsoft.Windows.Controls
{
public delegate void CheckListBoxSelectionChangedEventHandler(object sender, CheckListBoxSelectionChangedEventArgs e);
public class CheckListBoxSelectionChangedEventArgs : RoutedEventArgs
{
public object Item { get; private set; }
public CheckListBoxSelectionChangedEventArgs(RoutedEvent routedEvent, object source, object item)
: base(routedEvent, source)
{
Item = item;
}
}
}

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

@ -36,7 +36,7 @@
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<CheckBox Name="PART_CheckBox" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}" <CheckBox Name="PART_CheckBox" IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}}"
VerticalAlignment="Center" Focusable="False" Margin="3,1,5,1"/> VerticalAlignment="Center" Focusable="False" Margin="3,1,5,1"/>
<Border Grid.Column="1"> <Border Grid.Column="1">
<ContentPresenter Margin="2" ContentSource="Content" /> <ContentPresenter Margin="2" ContentSource="Content" />

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -156,7 +156,7 @@
<Compile Include="Calculator\Implementation\CalculatorCommands.cs" /> <Compile Include="Calculator\Implementation\CalculatorCommands.cs" />
<Compile Include="CheckListBox\Implementation\CheckListBoxItem.cs" /> <Compile Include="CheckListBox\Implementation\CheckListBoxItem.cs" />
<Compile Include="CheckListBox\Implementation\CheckListBox.cs" /> <Compile Include="CheckListBox\Implementation\CheckListBox.cs" />
<Compile Include="CheckListBox\Implementation\CheckListBoxSelectionChangedEventArgs.cs" /> <Compile Include="CheckListBox\Implementation\CheckListBoxCheckedChangedEventArgs.cs" />
<Compile Include="ChildWindow\Implementation\ChildWindow.cs" /> <Compile Include="ChildWindow\Implementation\ChildWindow.cs" />
<Compile Include="ChildWindow\Implementation\WindowStartupLocation.cs" /> <Compile Include="ChildWindow\Implementation\WindowStartupLocation.cs" />
<Compile Include="ChildWindow\Implementation\WindowState.cs" /> <Compile Include="ChildWindow\Implementation\WindowState.cs" />

Loading…
Cancel
Save