All the controls missing in WPF. Over 1 million downloads.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
5.1 KiB

<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>