1

TextBlock の LeftAlignment のようなプロパティに似た 2 つのオプション (Left と Right) を持つ DependencyProperty を作成したいと考えています。

これに関連するコードを知っている人はいますか?これまでのところ、以下のように単純な 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); }
}
4

1 に答える 1

3

たとえば、プロパティのタイプを文字列ではなく列挙型に設定するだけです。

    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 ) );
于 2009-05-05T09:24:12.577 に答える