Hi,
You can use the ColorPicker as an editor for brushes. Here's an example :
You can use the ColorPicker as an editor for brushes. Here's an example :
<Window.Resources>
<local:MyColorConverter x:Key="MyColorConverter" />
</Window.Resources>
<Grid>
<xctk:PropertyGrid x:Name="_propertyGrid">
<xctk:PropertyGrid.EditorDefinitions>
<xctk:EditorTemplateDefinition TargetProperties="Background">
<xctk:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<xctk:ColorPicker SelectedColor="{Binding Value, Converter={StaticResource MyColorConverter}}" />
</DataTemplate>
</xctk:EditorTemplateDefinition.EditingTemplate>
</xctk:EditorTemplateDefinition>
</xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
_propertyGrid.SelectedObject = new MyObject()
{
Name = "TEST",
Background = Brushes.Red,
FontFamily = new FontFamily("Comic Sans MS")
};
}
}
public class MyObject
{
public string Name
{
get;
set;
}
public Brush Background
{
get;
set;
}
public FontFamily FontFamily
{
get;
set;
}
}
public class MyColorConverter : IValueConverter
{
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
if( value is SolidColorBrush )
{
return ((SolidColorBrush)value).Color;
}
return null;
}
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
return new SolidColorBrush( (Color)value );
}
}