Browse Source

PropertyGrid: Added PropertyGrid examples to the Samples application.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
3b3e10da10
  1. 5
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/PropertyGridModule.cs
  2. 9
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Resources/LastNameUserControlEditor.xaml
  3. 39
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Resources/LastNameUserControlEditor.xaml.cs
  4. 42
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Samples.Modules.PropertyGrid.csproj
  5. 70
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomEditors.xaml
  6. 157
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomEditors.xaml.cs
  7. 23
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml
  8. 80
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml.cs
  9. 21
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/DefaultEditors.xaml
  10. 104
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/DefaultEditors.xaml.cs
  11. 23
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/ExpandableProperties.xaml
  12. 62
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/ExpandableProperties.xaml.cs
  13. 65
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml
  14. 3
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml.cs
  15. 10
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/NavigationView.xaml
  16. 30
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/SpecifyingProperties.xaml
  17. 104
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/SpecifyingProperties.xaml.cs
  18. 12
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/IEditorDefinition.cs
  19. 4
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs

5
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/PropertyGridModule.cs

@ -20,6 +20,11 @@ namespace Samples.Modules.PropertyGrid
protected override void RegisterViewsAndTypes()
{
Container.RegisterNavigationType(typeof(HomeView));
Container.RegisterNavigationType(typeof(CustomEditors));
Container.RegisterNavigationType(typeof(CustomItemsSource));
Container.RegisterNavigationType(typeof(DefaultEditors));
Container.RegisterNavigationType(typeof(ExpandableProperties));
Container.RegisterNavigationType(typeof(SpecifyingProperties));
}
}
}

9
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Resources/LastNameUserControlEditor.xaml

@ -0,0 +1,9 @@
<UserControl x:Class="Samples.Modules.PropertyGrid.LastNameUserControlEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="_uc">
<StackPanel>
<TextBox Text="{Binding Value, ElementName=_uc}" Background="YellowGreen" />
<Button Click="Button_Click">Clear</Button>
</StackPanel>
</UserControl>

39
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Resources/LastNameUserControlEditor.xaml.cs

@ -0,0 +1,39 @@
using System.Windows;
using System.Windows.Controls;
using Microsoft.Windows.Controls.PropertyGrid.Editors;
using System.Windows.Data;
namespace Samples.Modules.PropertyGrid
{
/// <summary>
/// Interaction logic for LastNameUserControlEditor.xaml
/// </summary>
public partial class LastNameUserControlEditor : UserControl, ITypeEditor
{
public LastNameUserControlEditor()
{
InitializeComponent();
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(LastNameUserControlEditor), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Value = string.Empty;
}
public FrameworkElement ResolveEditor(Microsoft.Windows.Controls.PropertyGrid.PropertyItem propertyItem)
{
Binding binding = new Binding("Value");
binding.Source = propertyItem;
binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
BindingOperations.SetBinding(this, LastNameUserControlEditor.ValueProperty, binding);
return this;
}
}
}

42
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Samples.Modules.PropertyGrid.csproj

@ -61,6 +61,9 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Resources\LastNameUserControlEditor.xaml.cs">
<DependentUpon>LastNameUserControlEditor.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGridModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
@ -75,12 +78,27 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Views\CustomEditors.xaml.cs">
<DependentUpon>CustomEditors.xaml</DependentUpon>
</Compile>
<Compile Include="Views\CustomItemsSource.xaml.cs">
<DependentUpon>CustomItemsSource.xaml</DependentUpon>
</Compile>
<Compile Include="Views\DefaultEditors.xaml.cs">
<DependentUpon>DefaultEditors.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ExpandableProperties.xaml.cs">
<DependentUpon>ExpandableProperties.xaml</DependentUpon>
</Compile>
<Compile Include="Views\HomeView.xaml.cs">
<DependentUpon>HomeView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\NavigationView.xaml.cs">
<DependentUpon>NavigationView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SpecifyingProperties.xaml.cs">
<DependentUpon>SpecifyingProperties.xaml</DependentUpon>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@ -102,6 +120,26 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Resources\LastNameUserControlEditor.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CustomEditors.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CustomItemsSource.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DefaultEditors.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ExpandableProperties.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\HomeView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -110,6 +148,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SpecifyingProperties.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

70
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomEditors.xaml

@ -0,0 +1,70 @@
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.CustomEditors"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Custom Editors">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="This example demonstrates the various methods of creating and using custom editors. You can supply your own editor based on a Type, a property name, or both. To supply your own editor for a property you have to create an EditorDefinition for the PropertyGrid."
TextWrapping="Wrap" />
<StackPanel Grid.Row="1" Margin="10">
<TextBlock Text="Custom Editors with a DataTemplate:" Style="{StaticResource Header}" />
<TextBlock Text="You can override the default editors with your own custom editors with a DataTemplate. Simply define an EditorDefinition that either targets a Type, property name, or both and set the EditorDefinition.EditorTemplate to an instance of a DataTemplate. Be sure to bind your custom editor to the bound property item's Value property." TextWrapping="Wrap"/>
<extToolkit:PropertyGrid x:Name="_propertyGrid1" Width="450" Margin="10">
<extToolkit:PropertyGrid.EditorDefinitions>
<!-- This EditorDefinition will provide a TextBox to any property that is of type HorizontalAlignment, replacing the default ComboBox editor. -->
<extToolkit:EditorDefinition TargetType="{x:Type HorizontalAlignment}">
<extToolkit:EditorDefinition.EditorTemplate>
<DataTemplate>
<TextBox Background="Green" Text="{Binding Value}" /> <!-- Always bind your editor's value to the bound property's Value -->
</DataTemplate>
</extToolkit:EditorDefinition.EditorTemplate>
</extToolkit:EditorDefinition>
<!-- This EditorDefinition will provide a TextBlock to any property that has any of the defined property names, replacing the default editor. -->
<extToolkit:EditorDefinition>
<extToolkit:EditorDefinition.PropertiesDefinitions>
<extToolkit:PropertyDefinition Name="Age" />
<extToolkit:PropertyDefinition Name="WritingFont" />
<extToolkit:PropertyDefinition Name="Spouse" />
</extToolkit:EditorDefinition.PropertiesDefinitions>
<extToolkit:EditorDefinition.EditorTemplate>
<DataTemplate>
<TextBlock Background="Yellow" Text="{Binding Value}" />
</DataTemplate>
</extToolkit:EditorDefinition.EditorTemplate>
</extToolkit:EditorDefinition>
<!-- This EditorDefinition will provide a TextBox to any property that is of type Boolean and that has any of the defined property names, replacing the default editor. -->
<extToolkit:EditorDefinition TargetType="{x:Type sys:Boolean}">
<extToolkit:EditorDefinition.PropertiesDefinitions>
<extToolkit:PropertyDefinition Name="DateOfBirth" />
<extToolkit:PropertyDefinition Name="LastName" />
</extToolkit:EditorDefinition.PropertiesDefinitions>
<extToolkit:EditorDefinition.EditorTemplate>
<DataTemplate>
<TextBox Background="Red" Text="{Binding Value}" />
</DataTemplate>
</extToolkit:EditorDefinition.EditorTemplate>
</extToolkit:EditorDefinition>
</extToolkit:PropertyGrid.EditorDefinitions>
</extToolkit:PropertyGrid>
</StackPanel>
<StackPanel Grid.Row="2" Margin="10">
<TextBlock Text="Custom Editors with an Attribute:" Style="{StaticResource Header}" />
<TextBlock Text="You can supply editors for a property by using the System.ComponentModel.EditorAttribute. In order to provide an editor with an attribute, the editor MUST implement the ITypeEditor interface. Your editor can be a simple class or a complex UserControl." TextWrapping="Wrap" />
<extToolkit:PropertyGrid x:Name="_propertyGrid2" Width="450" Margin="10"/>
</StackPanel>
</Grid>
</infControls:DemoView>

157
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomEditors.xaml.cs

@ -0,0 +1,157 @@
using Samples.Infrastructure.Controls;
using System.ComponentModel;
using System.Collections.Generic;
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Data;
namespace Samples.Modules.PropertyGrid.Views
{
/// <summary>
/// Interaction logic for CustomEditors.xaml
/// </summary>
public partial class CustomEditors : DemoView
{
public CustomEditors()
{
InitializeComponent();
_propertyGrid1.SelectedObject = Person.CreatePerson();
_propertyGrid2.SelectedObject = CustomAttributEditorPerson.CreateCustomAttributEditorPerson();
}
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
[Category("Information")]
[DisplayName("Date of Birth")]
[Description("This property uses the DateTimeUpDown as the default editor.")]
public DateTime DateOfBirth { get; set; }
[DisplayName("Grade Point Average")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double GradePointAvg { get; set; }
[Category("Information")]
[Description("This property uses the IntegerUpDown as the default editor.")]
public int Age { get; set; }
[Category("Information")]
[DisplayName("Is Male")]
[Description("This property uses a CheckBox as the default editor.")]
public bool IsMale { get; set; }
[Category("Information")]
[DisplayName("Favorite Color")]
[Description("This property uses the ColorPicker as the default editor.")]
public Color FavoriteColor { get; set; }
[Category("Writing")]
[DisplayName("Writing Hand")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public HorizontalAlignment WritingHand { get; set; }
[Category("Writing")]
[DisplayName("Writing Font")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public FontFamily WritingFont { get; set; }
[Category("Writing")]
[DisplayName("Writing Font Size")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double WritingFontSize { get; set; }
[Category("Conections")]
[DisplayName("Pet Names")]
[Description("This property uses the PrimitiveTypeCollectionEditor as the default editor.")]
public List<String> PetNames { get; set; }
[Category("Conections")]
[Description("This property uses the CollectionEditor as the default editor.")]
public List<Person> Friends { get; set; }
[Category("Conections")]
[Description("This property is a complex property and has no default editor.")]
public Person Spouse { get; set; }
public static Person CreatePerson()
{
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
person.DateOfBirth = new DateTime(1975, 1, 23);
person.Age = DateTime.Today.Year - person.DateOfBirth.Year;
person.GradePointAvg = 3.98;
person.IsMale = true;
person.FavoriteColor = Colors.Blue;
person.WritingHand = System.Windows.HorizontalAlignment.Right;
person.WritingFont = new FontFamily("Arial");
person.WritingFontSize = 12.5;
person.PetNames = new List<string>() { "Pet 1", "Pet 2", "Pet 3" };
person.Friends = new List<Person>() { new Person() { FirstName = "First", LastName = "Friend" }, new Person() { FirstName = "Second", LastName = "Friend" } };
person.Spouse = new Person() { FirstName = "Jane", LastName = "Doe" };
return person;
}
}
public class CustomAttributEditorPerson
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
//This custom editor is a Class that implements the ITypeEditor interface
[Editor(typeof(FirstNameEditor), typeof(FirstNameEditor))]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
//This custom editor is a UserControl that implements the ITypeEditor interface
[Editor(typeof(LastNameUserControlEditor), typeof(LastNameUserControlEditor))]
public string LastName { get; set; }
[Category("Information")]
[DisplayName("Date of Birth")]
[Description("This property uses the DateTimeUpDown as the default editor.")]
public DateTime DateOfBirth { get; set; }
public static CustomAttributEditorPerson CreateCustomAttributEditorPerson()
{
var person = new CustomAttributEditorPerson();
person.FirstName = "John";
person.LastName = "Doe";
person.DateOfBirth = new DateTime(1975, 1, 23);
return person;
}
}
}
//Custom editors that are used as attributes MUST implement the ITypeEditor interface.
public class FirstNameEditor : Microsoft.Windows.Controls.PropertyGrid.Editors.ITypeEditor
{
public FrameworkElement ResolveEditor(Microsoft.Windows.Controls.PropertyGrid.PropertyItem propertyItem)
{
TextBox textBox = new TextBox();
textBox.Background = new SolidColorBrush(Colors.Red);
//create the binding from the bound property item to the editor
var _binding = new Binding("Value"); //bind to the Value property of the PropertyItem
_binding.Source = propertyItem;
_binding.ValidatesOnExceptions = true;
_binding.ValidatesOnDataErrors = true;
_binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
BindingOperations.SetBinding(textBox, TextBox.TextProperty, _binding);
return textBox;
}
}
}

23
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml

@ -0,0 +1,23 @@
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.CustomItemsSource"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="Custom ItemsSource">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Sometimes it is desirable to want to provide a collection of values represented by a ComboBox for a given property. The PropertyGrid supports this scenario by create a class that implements IItemsSource and decorating your property with the ItemsSourceAttribute."
TextWrapping="Wrap" />
<StackPanel Grid.Row="1" Margin="10">
<TextBlock Text="Providing a Custom ItemsSource:" Style="{StaticResource Header}" />
<TextBlock Text="This example uses a collection of Doubles to represent the available options for the WritingFontSize property." TextWrapping="Wrap"/>
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10"/>
</StackPanel>
</Grid>
</infControls:DemoView>

80
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml.cs

@ -0,0 +1,80 @@
using Samples.Infrastructure.Controls;
using System.ComponentModel;
using System.Collections.Generic;
using System;
using System.Windows.Media;
using System.Windows;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
namespace Samples.Modules.PropertyGrid.Views
{
/// <summary>
/// Interaction logic for CustomItemsSource.xaml
/// </summary>
public partial class CustomItemsSource : DemoView
{
public CustomItemsSource()
{
InitializeComponent();
_propertyGrid.SelectedObject = Person.CreatePerson();
}
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
[Category("Information")]
[DisplayName("Date of Birth")]
[Description("This property uses the DateTimeUpDown as the default editor.")]
public DateTime DateOfBirth { get; set; }
[Category("Writing")]
[DisplayName("Writing Hand")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public HorizontalAlignment WritingHand { get; set; }
[Category("Writing")]
[DisplayName("Writing Font")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public FontFamily WritingFont { get; set; }
[Category("Writing")]
[DisplayName("Writing Font Size")]
[Description("This property uses the DoubleUpDown as the default editor.")]
[ItemsSource(typeof(FontSizeItemsSource))]
public double WritingFontSize { get; set; }
public static Person CreatePerson()
{
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
person.DateOfBirth = new DateTime(1975, 1, 23);
person.WritingHand = System.Windows.HorizontalAlignment.Right;
person.WritingFont = new FontFamily("Arial");
person.WritingFontSize = 12.0;
return person;
}
}
}
public class FontSizeItemsSource : IItemsSource
{
public IList<object> GetValues()
{
List<object> sizes = new List<object>()
{
5.0,5.5,6.0,6.5,7.0,7.5,8.0,8.5,9.0,9.5,10.0,12.0,14.0,16.0,18.0,20.0
};
return sizes;
}
}
}

21
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/DefaultEditors.xaml

@ -0,0 +1,21 @@
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.DefaultEditors"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="Default Editors">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="This example demonstrates the default editors provided by the PropertyGrid."
TextWrapping="Wrap" />
<StackPanel Grid.Row="1" Margin="10">
<TextBlock Text="Default Editors:" Style="{StaticResource Header}" />
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10"/>
</StackPanel>
</Grid>
</infControls:DemoView>

104
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/DefaultEditors.xaml.cs

@ -0,0 +1,104 @@
using Samples.Infrastructure.Controls;
using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.ComponentModel;
using System.Windows;
namespace Samples.Modules.PropertyGrid.Views
{
/// <summary>
/// Interaction logic for DefaultEditors.xaml
/// </summary>
public partial class DefaultEditors : DemoView
{
public DefaultEditors()
{
InitializeComponent();
_propertyGrid.SelectedObject = Person.CreatePerson();
}
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
[Category("Information")]
[DisplayName("Date of Birth")]
[Description("This property uses the DateTimeUpDown as the default editor.")]
public DateTime DateOfBirth { get; set; }
[DisplayName("Grade Point Average")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double GradePointAvg { get; set; }
[Category("Information")]
[Description("This property uses the IntegerUpDown as the default editor.")]
public int Age { get; set; }
[Category("Information")]
[DisplayName("Is Male")]
[Description("This property uses a CheckBox as the default editor.")]
public bool IsMale { get; set; }
[Category("Information")]
[DisplayName("Favorite Color")]
[Description("This property uses the ColorPicker as the default editor.")]
public Color FavoriteColor { get; set; }
[Category("Writing")]
[DisplayName("Writing Hand")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public HorizontalAlignment WritingHand { get; set; }
[Category("Writing")]
[DisplayName("Writing Font")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public FontFamily WritingFont { get; set; }
[Category("Writing")]
[DisplayName("Writing Font Size")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double WritingFontSize { get; set; }
[Category("Conections")]
[DisplayName("Pet Names")]
[Description("This property uses the PrimitiveTypeCollectionEditor as the default editor.")]
public List<String> PetNames { get; set; }
[Category("Conections")]
[Description("This property uses the CollectionEditor as the default editor.")]
public List<Person> Friends { get; set; }
[Category("Conections")]
[Description("This property is a complex property and has no default editor.")]
public Person Spouse { get; set; }
public static Person CreatePerson()
{
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
person.DateOfBirth = new DateTime(1975, 1, 23);
person.Age = DateTime.Today.Year - person.DateOfBirth.Year;
person.GradePointAvg = 3.98;
person.IsMale = true;
person.FavoriteColor = Colors.Blue;
person.WritingHand = System.Windows.HorizontalAlignment.Right;
person.WritingFont = new FontFamily("Arial");
person.WritingFontSize = 12.5;
person.PetNames = new List<string>() { "Pet 1", "Pet 2", "Pet 3" };
person.Friends = new List<Person>() { new Person() { FirstName = "First", LastName = "Friend" }, new Person() { FirstName = "Second", LastName = "Friend" } };
person.Spouse = new Person() { FirstName = "Jane", LastName = "Doe" };
return person;
}
}
}
}

23
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/ExpandableProperties.xaml

@ -0,0 +1,23 @@
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.ExpandableProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="Exandable Properties">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Sometimes it is neccessary to show the properties of a complex object. The PropertyGrid supports this scenario and allows you to drill down into a property's heirarchy. To enable this behavior you must decorate your property with the ExpandableObject attribute."
TextWrapping="Wrap" />
<StackPanel Grid.Row="1" Margin="10">
<TextBlock Text="Expandable Properties:" Style="{StaticResource Header}" />
<TextBlock Text="In this example the Spouse property has been decorated with the ExpandableObject attribute. Notice how you can drill down into the Spouse properties." TextWrapping="Wrap" />
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" />
</StackPanel>
</Grid>
</infControls:DemoView>

62
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/ExpandableProperties.xaml.cs

@ -0,0 +1,62 @@
using Samples.Infrastructure.Controls;
using System.ComponentModel;
using System.Collections.Generic;
using System;
using System.Windows.Media;
using System.Windows;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
namespace Samples.Modules.PropertyGrid.Views
{
/// <summary>
/// Interaction logic for ExpandableProperties.xaml
/// </summary>
public partial class ExpandableProperties : DemoView
{
public ExpandableProperties()
{
InitializeComponent();
_propertyGrid.SelectedObject = Person.CreatePerson();
}
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
[Category("Writing")]
[DisplayName("Writing Font")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public FontFamily WritingFont { get; set; }
[Category("Writing")]
[DisplayName("Writing Font Size")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double WritingFontSize { get; set; }
[Category("Conections")]
[Description("This property is a complex property and has no default editor.")]
[ExpandableObject]
public Person Spouse { get; set; }
public static Person CreatePerson()
{
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
person.WritingFont = new FontFamily("Arial");
person.WritingFontSize = 12.5;
person.Spouse = new Person() { FirstName = "Jane", LastName = "Doe" };
return person;
}
}
}
}

65
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml

@ -2,8 +2,67 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
Title="PropertyGrid" >
<Grid>
<TextBlock Text="PropertyGrid View" />
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="PropertyGrid" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="The PropertyGrid control allows you inspect and edit properties of an object. This PropertyGrid allows you do autogenerate all properties or specify the specific properties you want to display. You can use the standard editors that are provided with the PropertyGrid or you can use custom editors that target a Type, specific properties, or both. The PropertyGrid also supports complex properties, which allows you to drill down into a nested property hierarchy."
TextWrapping="Wrap" />
<GroupBox Header="Features" Grid.Row="1" Margin="5" >
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Display Sumary:" VerticalAlignment="Center" />
<CheckBox x:Name="_displaySummary" Grid.Column="1" IsChecked="True" VerticalAlignment="Center" Margin="5" ToolTip="Shows/Hides the summary panel of the PropertyGrid."/>
<TextBlock Text="Filter:" VerticalAlignment="Center" Grid.Row="1" />
<extToolkit:WatermarkTextBox x:Name="_filter" Grid.Row="1" Grid.Column="1"
Watermark="Search"
VerticalAlignment="Center" Margin="5" ToolTip="Filters the properties within the PropertyGrid."/>
<TextBlock Text="Is Categorized:" VerticalAlignment="Center" Grid.Column="2" />
<CheckBox x:Name="_isCategorized" Grid.Column="3" IsChecked="True" VerticalAlignment="Center" Margin="5" ToolTip="Gets/Sets the layout of the PropertyGrid."/>
<TextBlock Text="Show Advanced Options:" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2" />
<CheckBox x:Name="_showAdvancedOptions" Grid.Row="1" Grid.Column="3" IsChecked="True" VerticalAlignment="Center" Margin="5" ToolTip="Shows/Hides the advanced options menu next to a property."/>
</Grid>
</GroupBox>
<StackPanel Grid.Row="2" Margin="10">
<TextBlock Text="Usage:" Style="{StaticResource Header}" />
<TextBlock Text="To inspect an object simply set the PropertyGrid.SelectedObject property to an instance of the object you want to inspect."
TextWrapping="Wrap"/>
<Grid Height="400" Margin="10" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="_button" Height="200" Width="200" Margin="25" HorizontalAlignment="Center" VerticalAlignment="Center">Inspect Me</Button>
<extToolkit:PropertyGrid Grid.Column="1"
DisplaySummary="{Binding IsChecked, ElementName=_displaySummary}"
Filter="{Binding Text, ElementName=_filter, Mode=TwoWay}"
IsCategorized="{Binding IsChecked, ElementName=_isCategorized, Mode=TwoWay}"
ShowAdvancedOptions="{Binding IsChecked, ElementName=_showAdvancedOptions}"
SelectedObject="{Binding ElementName=_button}"/>
</Grid>
</StackPanel>
</Grid>
</infControls:DemoView>

3
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml.cs

@ -1,6 +1,5 @@
using System;
using Microsoft.Practices.Prism.Regions;
using Samples.Infrastructure.Controls;
using Microsoft.Practices.Prism.Regions;
namespace Samples.Modules.PropertyGrid.Views
{

10
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/NavigationView.xaml

@ -8,4 +8,14 @@
<Style TargetType="views:NavigationView" BasedOn="{StaticResource {x:Type TreeViewItem}}" />
</TreeViewItem.Resources>
<TreeViewItem Header="Editors">
<TreeViewItem Header="Default Editors" Tag="{x:Type views:DefaultEditors}" />
<TreeViewItem Header="Custom Editors" Tag="{x:Type views:CustomEditors}"/>
</TreeViewItem>
<TreeViewItem Header="Properties">
<TreeViewItem Header="Expandable Properties" Tag="{x:Type views:ExpandableProperties}"/>
<TreeViewItem Header="Specifying Properties" Tag="{x:Type views:SpecifyingProperties}"/>
<TreeViewItem Header="Providing an ItemsSource" Tag="{x:Type views:CustomItemsSource}"/>
</TreeViewItem>
</TreeViewItem>

30
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/SpecifyingProperties.xaml

@ -0,0 +1,30 @@
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.SpecifyingProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
Title="Specifying Properties">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="By default the propertyGrid will autogenerate all the properties for a given object. You can override this behavior by setting the AutoGenerateProperties property to False, and then provide a collection of PropertyDefinitions of the properties you would like to show."
TextWrapping="Wrap" />
<StackPanel Grid.Row="1" Margin="10">
<TextBlock Text="Specifying Properties:" Style="{StaticResource Header}" />
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10"
AutoGenerateProperties="False">
<!-- Only the following properties will be displayed in the PropertyGrid -->
<extToolkit:PropertyGrid.PropertyDefinitions>
<extToolkit:PropertyDefinition Name="FirstName" />
<extToolkit:PropertyDefinition Name="FavoriteColor" />
<extToolkit:PropertyDefinition Name="PetNames" />
</extToolkit:PropertyGrid.PropertyDefinitions>
</extToolkit:PropertyGrid>
</StackPanel>
</Grid>
</infControls:DemoView>

104
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/SpecifyingProperties.xaml.cs

@ -0,0 +1,104 @@
using Samples.Infrastructure.Controls;
using System.ComponentModel;
using System.Collections.Generic;
using System;
using System.Windows.Media;
using System.Windows;
namespace Samples.Modules.PropertyGrid.Views
{
/// <summary>
/// Interaction logic for SpecifyingProperties.xaml
/// </summary>
public partial class SpecifyingProperties : DemoView
{
public SpecifyingProperties()
{
InitializeComponent();
_propertyGrid.SelectedObject = Person.CreatePerson();
}
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
[Category("Information")]
[DisplayName("Date of Birth")]
[Description("This property uses the DateTimeUpDown as the default editor.")]
public DateTime DateOfBirth { get; set; }
[DisplayName("Grade Point Average")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double GradePointAvg { get; set; }
[Category("Information")]
[Description("This property uses the IntegerUpDown as the default editor.")]
public int Age { get; set; }
[Category("Information")]
[DisplayName("Is Male")]
[Description("This property uses a CheckBox as the default editor.")]
public bool IsMale { get; set; }
[Category("Information")]
[DisplayName("Favorite Color")]
[Description("This property uses the ColorPicker as the default editor.")]
public Color FavoriteColor { get; set; }
[Category("Writing")]
[DisplayName("Writing Hand")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public HorizontalAlignment WritingHand { get; set; }
[Category("Writing")]
[DisplayName("Writing Font")]
[Description("This property uses a ComboBox as the default editor. The ComboBox is auto populated with the enum values")]
public FontFamily WritingFont { get; set; }
[Category("Writing")]
[DisplayName("Writing Font Size")]
[Description("This property uses the DoubleUpDown as the default editor.")]
public double WritingFontSize { get; set; }
[Category("Conections")]
[DisplayName("Pet Names")]
[Description("This property uses the PrimitiveTypeCollectionEditor as the default editor.")]
public List<String> PetNames { get; set; }
[Category("Conections")]
[Description("This property uses the CollectionEditor as the default editor.")]
public List<Person> Friends { get; set; }
[Category("Conections")]
[Description("This property is a complex property and has no default editor.")]
public Person Spouse { get; set; }
public static Person CreatePerson()
{
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
person.DateOfBirth = new DateTime(1975, 1, 23);
person.Age = DateTime.Today.Year - person.DateOfBirth.Year;
person.GradePointAvg = 3.98;
person.IsMale = true;
person.FavoriteColor = Colors.Blue;
person.WritingHand = System.Windows.HorizontalAlignment.Right;
person.WritingFont = new FontFamily("Arial");
person.WritingFontSize = 12.5;
person.PetNames = new List<string>() { "Pet 1", "Pet 2", "Pet 3" };
person.Friends = new List<Person>() { new Person() { FirstName = "First", LastName = "Friend" }, new Person() { FirstName = "Second", LastName = "Friend" } };
person.Spouse = new Person() { FirstName = "Jane", LastName = "Doe" };
return person;
}
}
}
}

12
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/IEditorDefinition.cs

@ -1,12 +0,0 @@
using System;
using System.Windows;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public interface IEditorDefinition
{
DataTemplate EditorTemplate { get; set; }
PropertyDefinitionCollection PropertiesDefinitions { get; set; }
Type TargetType { get; set; }
}
}

4
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs

@ -36,14 +36,14 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //Category
#region Desription
#region Description
public string Description
{
get { return PropertyDescriptor.Description; }
}
#endregion //Desription
#endregion //Description
#region DisplayName

Loading…
Cancel
Save