19 changed files with 844 additions and 19 deletions
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue