WPF Designer & Custom Dependency Properties · Musings

WPF Designer & Custom Dependency Properties

We needed a custom WPF layout for a work project so we merrily set about extending Panel and implementing our MeasureOverride and ArrangeOverride methods. However, we had some issues with the designer not responding well to XAML changes for our custom dependency properties. The solution turned out to be simple. Register the property with FrameworkPropertyMetadata instead of PropertyMetadata and set the AffectsArrange and AffectsMeasure flags.

static DependencyProperty MyCustomMarginProperty
      = DependencyProperty.Register("MyCustomMargin",
                              typeof (double),
                              typeof (MyControl),
                              new FrameworkPropertyMetadata(default(double))
                                 {
                                    AffectsArrange = true,
                                    AffectsMeasure = true
                                 });