Browse Source

working on the CheckComboBox and CheckListBox. Do not use them, they are not ready.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
d89cbe19fa
  1. 45
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Color/Views/HomeView.xaml
  2. 129
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Color/Views/HomeView.xaml.cs
  3. 2
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.DateTime/Views/HomeView.xaml
  4. 6
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Text/Views/HomeView.xaml
  5. 24
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Text/Views/HomeView.xaml.cs
  6. 23
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Implementation/CheckComboBox.cs
  7. 86
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/Selector.cs

45
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Color/Views/HomeView.xaml

@ -2,8 +2,49 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure" xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Color Controls"> Title="Color Controls">
<Grid> <Grid Margin="25">
<TextBlock Text="Color View" /> <!--<DataGrid x:Name="_dataGrid"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Level" Binding="{Binding Level}" IsReadOnly="True" />
<DataGridTemplateColumn Header="Color">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<extToolkit:ColorPicker DisplayColorAndName="True" SelectedColor="{Binding Color, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>-->
<StackPanel>
<extToolkit:CheckComboBox x:Name="_combo" HorizontalAlignment="Center" VerticalAlignment="Center"
DisplayMemberPath="Color"
SelectedValuePath="Level"
SelectedItems="{Binding SelectedItems}" />
<!--<extToolkit:CheckComboBox x:Name="_combo" HorizontalAlignment="Center" VerticalAlignment="Center"
SelectedValue="{Binding SelectedValues}" />-->
<!--<ComboBox x:Name="_combo2" HorizontalAlignment="Center" VerticalAlignment="Center"
IsEditable="True"
DisplayMemberPath="Color"
/>-->
<extToolkit:CheckListBox x:Name="_listBox" Height="250"
DisplayMemberPath="Color"
SelectedValuePath="Level"
SelectedItems="{Binding SelectedItems}" />
<!--<extToolkit:CheckListBox x:Name="_listBox" Height="250"
SelectedValue="{Binding SelectedValues}"
/>-->
</StackPanel>
</Grid> </Grid>
</infControls:DemoView> </infControls:DemoView>

129
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Color/Views/HomeView.xaml.cs

@ -1,6 +1,9 @@
using System; using System;
using Samples.Infrastructure.Controls; using Samples.Infrastructure.Controls;
using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Prism.Regions;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Samples.Modules.Color.Views namespace Samples.Modules.Color.Views
{ {
@ -13,6 +16,132 @@ namespace Samples.Modules.Color.Views
public HomeView() public HomeView()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new Data();
//List<string> colors = new List<string>();
//colors.Add("1");
//colors.Add("2");
//colors.Add("3");
//colors.Add("4");
//colors.Add("5");
//colors.Add("6");
//colors.Add("7");
//colors.Add("8");
//colors.Add("9");
//colors.Add("10");
List<Person> colors = new List<Person>();
colors.Add(new Person(System.Windows.Media.Colors.Red, 0));
colors.Add(new Person(System.Windows.Media.Colors.Purple, 1));
colors.Add(new Person(System.Windows.Media.Colors.Coral, 2));
colors.Add(new Person(System.Windows.Media.Colors.MidnightBlue, 3));
colors.Add(new Person(System.Windows.Media.Colors.Green, 4));
colors.Add(new Person(System.Windows.Media.Colors.Red, 5));
colors.Add(new Person(System.Windows.Media.Colors.Purple, 6));
colors.Add(new Person(System.Windows.Media.Colors.SaddleBrown, 7));
colors.Add(new Person(System.Windows.Media.Colors.MidnightBlue, 8));
colors.Add(new Person(System.Windows.Media.Colors.Green, 9));
colors.Add(new Person(System.Windows.Media.Colors.Red, 10));
colors.Add(new Person(System.Windows.Media.Colors.Purple, 11));
colors.Add(new Person(System.Windows.Media.Colors.SaddleBrown, 12));
colors.Add(new Person(System.Windows.Media.Colors.MidnightBlue, 13));
colors.Add(new Person(System.Windows.Media.Colors.Green, 14));
colors.Add(new Person(System.Windows.Media.Colors.Red, 15));
colors.Add(new Person(System.Windows.Media.Colors.Purple, 16));
colors.Add(new Person(System.Windows.Media.Colors.SaddleBrown, 17));
colors.Add(new Person(System.Windows.Media.Colors.MidnightBlue, 18));
colors.Add(new Person(System.Windows.Media.Colors.Green, 19));
//_dataGrid.ItemsSource = colors;
//_chk.ItemsSource = colors;
_combo.ItemsSource = colors;
//_combo.SelectedValue = "1,3,5,7,9,";
_listBox.ItemsSource = colors;
//_listBox.DelimitedValue = "1,3,5,7,9,";
}
}
public class Data
{
private string _selectedValues;// = "1,3,5,7,9,";
public string SelectedValues
{
get
{
return _selectedValues;
}
set
{
_selectedValues = value;
}
} }
private ObservableCollection<Person> _selectedItems = new ObservableCollection<Person>()
{
new Person(System.Windows.Media.Colors.Red, 0),
new Person(System.Windows.Media.Colors.Coral, 2)
};
public ObservableCollection<Person> SelectedItems
{
get { return _selectedItems; }
set
{
_selectedItems = value;
}
}
} }
public class Person : INotifyPropertyChanged
{
private bool _isSelected;
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
OnPropertyChanged("IsSelected");
}
}
System.Windows.Media.Color _color;
public System.Windows.Media.Color Color
{
get { return _color; }
set
{
_color = value;
OnPropertyChanged("Color");
}
}
int _level;
public int Level
{
get { return _level; }
set { _level = value; OnPropertyChanged("Level"); }
}
public Person()
{
}
public Person(System.Windows.Media.Color color, int level)
{
this._color = color;
this._level = level;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
} }

2
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.DateTime/Views/HomeView.xaml

@ -5,6 +5,6 @@
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure" xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
Title="DateTime Controls"> Title="DateTime Controls">
<Grid> <Grid>
<TextBlock Text="DateTime controls" /> <extToolkit:DateTimePicker IsReadOnly="False" />
</Grid> </Grid>
</infControls:DemoView> </infControls:DemoView>

6
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Text/Views/HomeView.xaml

@ -2,8 +2,12 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure" xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="Text Controls"> Title="Text Controls">
<Grid> <Grid>
<TextBlock Text="Text View" /> <extToolkit:TokenizedTextBox x:Name="_textBox"
DisplayMemberPath="FullName"
SearchMemberPath="FirstName"
ValueMemberPath="Id" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" />
</Grid> </Grid>
</infControls:DemoView> </infControls:DemoView>

24
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Text/Views/HomeView.xaml.cs

@ -1,6 +1,7 @@
using System; using System;
using Samples.Infrastructure.Controls; using Samples.Infrastructure.Controls;
using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Prism.Regions;
using System.Collections.Generic;
namespace Samples.Modules.Text.Views namespace Samples.Modules.Text.Views
{ {
@ -13,6 +14,29 @@ namespace Samples.Modules.Text.Views
public HomeView() public HomeView()
{ {
InitializeComponent(); InitializeComponent();
_textBox.Text = "1;2;"; //is of object ids
_textBox.ItemsSource = new List<Email>()
{
new Email() { Id = 1, FirstName = "John", LastName = "Doe", EmailAddress = "john@test.com" },
new Email() { Id = 2, FirstName = "Jane", LastName = "Doe", EmailAddress = "jane@test.com" },
};
}
public class Email
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string FullName
{
get
{
return String.Format("{0}, {1}", LastName, FirstName);
}
}
} }
} }
} }

23
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Implementation/CheckComboBox.cs

@ -6,7 +6,7 @@ namespace Microsoft.Windows.Controls
{ {
public class CheckComboBox : Selector public class CheckComboBox : Selector
{ {
private bool _surpressTextUpdate; private bool _surpressTextUpdateFromSelectedValueChanged;
#region Constructors #region Constructors
@ -58,20 +58,33 @@ namespace Microsoft.Windows.Controls
#region Base Class Overrides #region Base Class Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
protected override void OnSelectedValueChanged(string oldValue, string newValue) protected override void OnSelectedValueChanged(string oldValue, string newValue)
{ {
base.OnSelectedValueChanged(oldValue, newValue); base.OnSelectedValueChanged(oldValue, newValue);
if (!_surpressTextUpdate) if (!_surpressTextUpdateFromSelectedValueChanged)
UpdateTextFromSelectedValue(); UpdateTextFromSelectedValue();
} }
protected override void OnSelectedItemsCollectionChanged(object item, bool remove)
{
_surpressTextUpdateFromSelectedValueChanged = true;
base.OnSelectedItemsCollectionChanged(item, remove);
UpdateDisplayText(item, remove);
_surpressTextUpdateFromSelectedValueChanged = false;
}
protected override void Update(object item, bool remove) protected override void Update(object item, bool remove)
{ {
_surpressTextUpdate = true; _surpressTextUpdateFromSelectedValueChanged = true;
base.Update(item, remove); base.Update(item, remove);
UpdateDisplayText(item, remove); UpdateDisplayText(item, remove);
_surpressTextUpdate = false; _surpressTextUpdateFromSelectedValueChanged = false;
} }
#endregion //Base Class Overrides #endregion //Base Class Overrides
@ -112,8 +125,6 @@ namespace Microsoft.Windows.Controls
private void UpdateTextFromSelectedValue() private void UpdateTextFromSelectedValue()
{ {
UpdateText(String.Empty);
if (!String.IsNullOrEmpty(SelectedValue)) if (!String.IsNullOrEmpty(SelectedValue))
{ {
string[] values = SelectedValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries); string[] values = SelectedValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries);

86
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/Selector.cs

@ -6,6 +6,7 @@ using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Input; using System.Windows.Input;
using System.Collections.Specialized;
namespace Microsoft.Windows.Controls.Primitives namespace Microsoft.Windows.Controls.Primitives
{ {
@ -88,18 +89,44 @@ namespace Microsoft.Windows.Controls.Primitives
protected virtual void OnSelectedItemsChanged(IList oldValue, IList newValue) protected virtual void OnSelectedItemsChanged(IList oldValue, IList newValue)
{ {
if (oldValue != null)
} {
var collection = oldValue as INotifyCollectionChanged;
if (collection != null)
collection.CollectionChanged -= SelectedItems_CollectionChanged;
}
#endregion SelectedItems if (newValue != null)
{
var collection = newValue as INotifyCollectionChanged;
if (collection != null)
collection.CollectionChanged += SelectedItems_CollectionChanged;
}
}
void SelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var item = e.NewItems[0];
OnSelectedItemsCollectionChanged(item, false);
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
var item = e.OldItems[0];
OnSelectedItemsCollectionChanged(item, true);
}
}
public static readonly DependencyProperty SelectedMemberPathProperty = DependencyProperty.Register("SelectedMemberPath", typeof(string), typeof(Selector), new UIPropertyMetadata(null)); protected virtual void OnSelectedItemsCollectionChanged(object item, bool remove)
public string SelectedMemberPath
{ {
get { return (string)GetValue(SelectedMemberPathProperty); } //var selectorItem = ItemContainerGenerator.ContainerFromItem(item) as SelectorItem;
set { SetValue(SelectedMemberPathProperty, value); } //selectorItem.IsSelected = !remove;
UpdateSelectedValue(item, remove);
} }
#endregion SelectedItems
#region SelectedValue #region SelectedValue
public static readonly DependencyProperty SelectedValueProperty = DependencyProperty.Register("SelectedValue", typeof(string), typeof(Selector), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedValueChanged)); public static readonly DependencyProperty SelectedValueProperty = DependencyProperty.Register("SelectedValue", typeof(string), typeof(Selector), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedValueChanged));
@ -157,36 +184,41 @@ namespace Microsoft.Windows.Controls.Primitives
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{ {
_surpressSelectionChanged = true; _surpressSelectionChanged = true;
bool isSelected = false;
var selectorItem = element as FrameworkElement; var selectorItem = element as FrameworkElement;
var value = item;
//let's check if we can find a value on the item using the SelectedValuePath property
if (!String.IsNullOrEmpty(SelectedValuePath))
{
var property = item.GetType().GetProperty(SelectedValuePath);
if (property != null)
{
value = property.GetValue(item, null);
}
}
//first try resolving SelectorItem.IsSelected by data binding to the SelectedMemeberPath property //now check to see if the SelectedValue string contains our value. If it does then set Selector.IsSelected to true
if (!String.IsNullOrEmpty(SelectedMemberPath)) if (!String.IsNullOrEmpty(SelectedValue) && SelectedValue.Contains(GetDelimitedValue(value)))
{ {
Binding selectedBinding = new Binding(SelectedMemberPath); isSelected = true;
selectedBinding.Mode = BindingMode.TwoWay;
selectedBinding.Source = item;
selectorItem.SetBinding(SelectorItem.IsSelectedProperty, selectedBinding);
} }
else else if (SelectedItems != null)
{ {
//if the SelectedMemberPath property is not set, then default to the value of the item //if we get here we could find the value in the SelectedValue property, so lets search the SelectedItems for a match
var value = item; foreach (object selectedItem in SelectedItems)
//now let's check if we can find a value on the item using the SelectedValuePath property
if (!String.IsNullOrEmpty(SelectedValuePath))
{ {
var property = item.GetType().GetProperty(SelectedValuePath); //a match was found so select it and get the hell out of here
if (property != null) if (value.Equals(GetItemValue(selectedItem)))
{ {
value = property.GetValue(item, null); isSelected = true;
break;
} }
} }
//now check to see if the SelectedValue string contains our value. If it does then set Selector.IsSelected to true
if (!String.IsNullOrEmpty(SelectedValue) && SelectedValue.Contains(GetDelimitedValue(value)))
selectorItem.SetValue(SelectorItem.IsSelectedProperty, true);
} }
selectorItem.SetValue(SelectorItem.IsSelectedProperty, isSelected);
base.PrepareContainerForItemOverride(element, item); base.PrepareContainerForItemOverride(element, item);
_surpressSelectionChanged = false; _surpressSelectionChanged = false;
} }
@ -405,7 +437,7 @@ namespace Microsoft.Windows.Controls.Primitives
public delegate void SelectedItemChangedEventHandler(object sender, SelectedItemChangedEventArgs e); public delegate void SelectedItemChangedEventHandler(object sender, SelectedItemChangedEventArgs e);
public class SelectedItemChangedEventArgs : RoutedEventArgs public class SelectedItemChangedEventArgs : RoutedEventArgs
{ {
public bool IsSelected {get;private set;} public bool IsSelected { get; private set; }
public object Item { get; private set; } public object Item { get; private set; }
public SelectedItemChangedEventArgs(RoutedEvent routedEvent, object source, object item, bool isSelected) public SelectedItemChangedEventArgs(RoutedEvent routedEvent, object source, object item, bool isSelected)

Loading…
Cancel
Save