2016-10-03 99 views
0

我已經擴展this example for a RadialPanelStartPositionLayoutDirection依賴屬性:當我更改這些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都不會重新計算控件的佈局。你需要告訴框架給定屬性影響佈局。

使用FrameworkPropertyMetadataFrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectArrange而不是PropertyMetadata這兩個屬性,框架將在您改變之後運行Panel的度量/排列。

相關問題