Custom DependencyProperty
I want to create a DependencyProperty with two parameters (left and right) similar to the LeftElignment properties in the TextBlock.
Does anyone know the code related to this? So far I have created simple DependencyProperty as shown below:
public static readonly DependencyProperty AlignProperty = DependencyProperty.Register("Align", typeof(string), typeof(HalfCurvedRectangle), new FrameworkPropertyMetadata("Left", FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
[TypeConverter(typeof(StringConverter))]
public string Align
{
get { return (string)base.GetValue(AlignProperty); }
set { base.SetValue(AlignProperty, value); }
}
+1
source to share
1 answer
Just specify the property type for the enum type instead of a string, for example:
public enum BrushTypes
{
Solid,
Gradient
}
public BrushTypes BrushType
{
get { return ( BrushTypes )GetValue( BrushTypeProperty ); }
set { SetValue( BrushTypeProperty, value ); }
}
public static readonly DependencyProperty BrushTypeProperty =
DependencyProperty.Register( "BrushType",
typeof( BrushTypes ),
typeof( MyClass ) );
+3
source to share