Пользовательские DependencyProperty - PullRequest
1 голос
/ 05 мая 2009

Я хочу создать свойство DependencyProperty с 2 параметрами (слева и справа), аналогично свойствам, подобным LeftAlignment в TextBlock.

Кто-нибудь знает код, связанный с этим? Пока я создал только простые DependencyPropertys, как показано ниже:

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 Ответ

3 голосов
/ 05 мая 2009

Просто установите тип свойства в тип enum вместо строки, например:

    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 ) );
...