Browse Source

PropertyGrid: working on collection editor

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
dac6d6469e
  1. 14
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml
  2. 45
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml.cs
  3. 29
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml
  4. 48
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs
  5. 11
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  6. 14
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

14
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml

@ -0,0 +1,14 @@
<UserControl x:Class="Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="(Collection)" VerticalAlignment="Center" />
<Button Grid.Column="1"
Content=" ... "
Click="Button_Click"/>
</Grid>
</UserControl>

45
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml.cs

@ -0,0 +1,45 @@
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.PropertyGrid.Editors
{
/// <summary>
/// Interaction logic for CollectionEditor.xaml
/// </summary>
public partial class CollectionEditor : UserControl, ITypeEditor
{
PropertyItem _item;
public CollectionEditor()
{
InitializeComponent();
}
public void Attach(PropertyItem propertyItem)
{
_item = propertyItem;
}
public FrameworkElement ResolveEditor()
{
return this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CollectionEditorDialog editor = new CollectionEditorDialog(_item);
editor.ShowDialog();
}
}
}

29
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml

@ -0,0 +1,29 @@
<Window x:Class="Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"
Title="Collection Editor" Height="400" Width="800" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox x:Name="_listBox" />
<propertyGrid:PropertyGrid x:Name="_propertyGrid" Grid.Column="1" SelectedObject="{Binding SelectedItem, ElementName=_listBox}" />
</Grid>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5" >
<Button Width="65" Margin="2" Click="Button_Click" >OK</Button>
<!--<Button Width="65" Margin="2">Cancel</Button>-->
</StackPanel>
</Grid>
</Window>

48
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs

@ -0,0 +1,48 @@
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.Shapes;
using System.Collections;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
/// <summary>
/// Interaction logic for CollectionEditorDialog.xaml
/// </summary>
public partial class CollectionEditorDialog : Window
{
PropertyItem _item;
public CollectionEditorDialog()
{
InitializeComponent();
}
public CollectionEditorDialog(PropertyItem item)
: this()
{
_item = item;
_listBox.ItemsSource = _item.Value as IEnumerable;
}
//public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(object), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
//public object ItemsSource
//{
// get { return (object)GetValue(ItemsSourceProperty); }
// set { SetValue(ItemsSourceProperty, value); }
//}
private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

11
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs

@ -10,6 +10,7 @@ using System.ComponentModel;
using System.Windows.Input;
using Microsoft.Windows.Controls.PropertyGrid.Editors;
using Microsoft.Windows.Controls.PropertyGrid.Commands;
using System.Collections;
namespace Microsoft.Windows.Controls.PropertyGrid
{
@ -405,7 +406,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
if (propertyItem.IsReadOnly)
editor = new TextBlockEditor();
else if (propertyItem.PropertyType == typeof(bool))
else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?))
editor = new CheckBoxEditor();
else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?))
editor = new DecimalUpDownEditor();
@ -413,7 +414,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
editor = new DoubleUpDownEditor();
else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?))
editor = new IntegerUpDownEditor();
else if (propertyItem.PropertyType == typeof(DateTime))
else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?))
editor = new DateTimeUpDownEditor();
else if ((propertyItem.PropertyType == typeof(Color)))
editor = new ColorEditor();
@ -421,6 +422,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid
editor = new EnumComboBoxEditor();
else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
editor = new FontComboBoxEditor();
else if (propertyItem.PropertyType.IsGenericType)
{
var interfaces = propertyItem.PropertyType.GetInterfaces();
if (interfaces.Contains(typeof(IEnumerable)))
editor = new CollectionEditor();
}
else
editor = new TextBoxEditor();
}

14
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -119,6 +119,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PropertyGrid\Implementation\Editors\CollectionEditor.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PropertyGrid\Implementation\Editors\CollectionEditorDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PropertyGrid\Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -215,6 +223,12 @@
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToImagePathConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToToolTipConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CheckBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CollectionEditor.xaml.cs">
<DependentUpon>CollectionEditor.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\Implementation\Editors\CollectionEditorDialog.xaml.cs">
<DependentUpon>CollectionEditorDialog.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\Implementation\Editors\ColorEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CustomTypeEditor.cs" />

Loading…
Cancel
Save