Browse Source

initial check-in of new CheckListBox. not ready for use yet. still playing with architecture.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
402858a083
  1. 117
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBox.cs
  2. 31
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Implementation/CheckListBoxItem.cs
  3. 61
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckListBox/Themes/Generic.xaml
  4. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  5. 6
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

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

@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.ComponentModel;
using System.Collections;
namespace Microsoft.Windows.Controls
{
public class CheckListBox : MultiSelector
{
static CheckListBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckListBox), new FrameworkPropertyMetadata(typeof(CheckListBox)));
}
#region Properties
public static readonly DependencyProperty CheckedMemberPathProperty = DependencyProperty.Register("CheckedMemberPath", typeof(string), typeof(CheckListBox), new UIPropertyMetadata(null));
public string CheckedMemberPath
{
get { return (string)GetValue(CheckedMemberPathProperty); }
set { SetValue(CheckedMemberPathProperty, value); }
}
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(CheckListBox), new PropertyMetadata((ICommand)null));
[TypeConverter(typeof(CommandConverter))]
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
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
protected override DependencyObject GetContainerForItemOverride()
{
return new CheckListBoxItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is CheckListBoxItem;
}
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
var checkListBoxItem = element as FrameworkElement;
if (!String.IsNullOrEmpty(CheckedMemberPath))
{
Binding isCheckedBinding = new Binding(CheckedMemberPath);
isCheckedBinding.Source = item;
checkListBoxItem.SetBinding(CheckListBoxItem.IsCheckedProperty, isCheckedBinding);
}
base.PrepareContainerForItemOverride(element, item);
}
#endregion //Base Class Overrides
}
}

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

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Microsoft.Windows.Controls
{
public class CheckListBoxItem : ContentControl
{
static CheckListBoxItem()
{
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
{
get { return (bool)GetValue(IsCheckedProperty); }
set { SetValue(IsCheckedProperty, value); }
}
}
}

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

@ -0,0 +1,61 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Windows.Controls"
xmlns:chrome="clr-namespace:Microsoft.Windows.Controls.Chromes"
xmlns:coreConverters="clr-namespace:Microsoft.Windows.Controls.Core.Converters">
<Style TargetType="{x:Type local:CheckListBox}">
<Setter Property="KeyboardNavigation.TabNavigation" Value="Once"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CheckListBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type local:CheckListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CheckListBoxItem}">
<Border x:Name="_background"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox Name="PART_CheckBox" IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
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">
<ContentPresenter Margin="2" ContentSource="Content" />
</Border>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsChecked" Value="true">
<Setter TargetName="_background" Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>-->
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="_background" Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -6,6 +6,7 @@
<ResourceDictionary Source="/WPFToolkit.Extended;component/ButtonSpinner/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/Calculator/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/CalculatorUpDown/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/CheckListBox/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/ChildWindow/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/ColorCanvas/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/ColorPicker/Themes/Generic.xaml" />

6
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -75,6 +75,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CheckListBox\Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ChildWindow\Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -146,6 +150,8 @@
<Compile Include="CalculatorUpDown\Implementation\CalculatorUpDown.cs" />
<Compile Include="Calculator\Implementation\Calculator.cs" />
<Compile Include="Calculator\Implementation\CalculatorCommands.cs" />
<Compile Include="CheckListBox\Implementation\CheckListBoxItem.cs" />
<Compile Include="CheckListBox\Implementation\CheckListBox.cs" />
<Compile Include="ChildWindow\Implementation\ChildWindow.cs" />
<Compile Include="ChildWindow\Implementation\WindowStartupLocation.cs" />
<Compile Include="ChildWindow\Implementation\WindowState.cs" />

Loading…
Cancel
Save