Hi,
I would replace
You can always replace
But in your case, you are defining a DataTemplate for all property of type "myType", which is not a PropertyType, but a class type.
You should use :
Complete Sample :
I would replace
<TextBlock Background="{Binding Value.Brush}" />
width<TextBlock Background="{Binding Value}" />
in order to see the TextBlock Background color.You can always replace
<xctk:TargetPropertyType Type="{x:Type local:myType}" />
with<xctk:TargetPropertyType Type="Brush" />
to target a property name instead of property type.But in your case, you are defining a DataTemplate for all property of type "myType", which is not a PropertyType, but a class type.
You should use :
<xctk:TargetPropertyType Type="{x:Type Brush}" />
So that all properties of type "Brush" will use your DataTemplate.Complete Sample :
<Grid>
<xctk:PropertyGrid x:Name="_propertyGrid"
SelectedObject="{Binding}">
<xctk:PropertyGrid.EditorDefinitions>
<xctk:EditorTemplateDefinition>
<xctk:EditorTemplateDefinition.TargetProperties>
<xctk:TargetPropertyType Type="{x:Type Brush}" />
</xctk:EditorTemplateDefinition.TargetProperties>
<xctk:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<Grid VerticalAlignment="Center"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Background="{Binding Value}" />
<Button Grid.Column="1"
Content=". . ." />
</Grid>
</DataTemplate>
</xctk:EditorTemplateDefinition.EditingTemplate>
</xctk:EditorTemplateDefinition>
</xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new myType() { Name = "Mike", Age = 30, Brush = Brushes.Green };
}
}
public class myType : DependencyObject
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
public static readonly DependencyProperty BrushProperty = DependencyProperty.Register( "Brush", typeof( Brush ), typeof( myType ) );
public Brush Brush
{
get
{
return ( Brush )GetValue( BrushProperty );
}
set
{
SetValue( BrushProperty, value );
}
}
}