2016-10-03 4 views
0

私はStartPositionLayoutDirection依存関係プロパティでthis example for a RadialPanelを拡張していますこれらのDependencyProperty値を変更するとデザイナが更新されないのはなぜですか?

public class RadialPanel : Panel 
{ 
    public RadialPanel() 
    { 
     StartPosition = StartPosition.Top; 
     LayoutDirection = LayoutDirection.Clockwise; 
    } 

    public StartPosition StartPosition 
    { 
     get { return (StartPosition)GetValue(StartPositionProperty); } 
     set { SetValue(StartPositionProperty, value); } 
    } 
    public static readonly DependencyProperty StartPositionProperty = 
     DependencyProperty.Register("StartPosition", typeof(StartPosition), typeof(RadialPanel), new PropertyMetadata(StartPosition.Top)); 


    public LayoutDirection LayoutDirection 
    { 
     get { return (LayoutDirection)GetValue(LayoutDirectionProperty); } 
     set { SetValue(LayoutDirectionProperty, value); } 
    } 
    public static readonly DependencyProperty LayoutDirectionProperty = 
     DependencyProperty.Register("LayoutDirection", typeof(LayoutDirection), typeof(RadialPanel), new PropertyMetadata(LayoutDirection.Clockwise)); 

// ... code from cited article 
} 

StartPositionLayoutDirection値が列挙型です:

public enum StartPosition 
{ 
    Left = 180, Top = 90, Right = 0, Bottom = -90 
} 

public enum LayoutDirection 
{ 
    Clockwise = -1, CounterClockwise = 1 
} 

数学は動作し、私はプロジェクトをビルドときすべてが更新されますが、私依存関係プロパティを使用すると、XAMLの値を変更したときにデザイナーが自動的に更新されると考えられました。

<local:RadialPanel StartPosition="Top" 
        LayoutDirection="CounterClockwise" > 

...ですが、そうではありません。 RadialPanelのChildrenを変更すると更新されますが、それだけです。

どうすればこの機能を有効にできますか?

+0

はい、プロジェクトコードが有効になっています...それは運が良かったです。 –

答えて

1

デフォルトでは、WPFはすべてのプロパティ変更後にコントロールのレイアウトを再計算しません。特定のプロパティがレイアウトに影響を与えることをフレームワークに伝える必要があります。 FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectArrange代わりの両方の性質上PropertyMetadata

使用FrameworkPropertyMetadata、およびフレームワークは、彼らが変更した後、あなたのPanelの配置/測定を実行します。

関連する問題