0

I created a WPF UserControl with a number of DependencyProperty custom properties, which all affect OnMeasure and call PropertyChangedCallback, e.g.:

private static readonly DependencyProperty ArrowStrokeThicknessProperty = DependencyProperty.Register("ArrowStrokeThickness", typeof(double), typeof(ProjectListTreePanel), new FrameworkPropertyMetadata(2d, FrameworkPropertyMetadataOptions.AffectsMeasure, PropertyChangedCallback), ValidateArrowStrokeThickness);

I'd rather put all these properties into a separate DependencyObject:

internal class MyArrowProperties : DependencyObject
{
  private static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register("StrokeThickness", typeof(double), typeof(MyArrowProperties), new FrameworkPropertyMetadata(2d, FrameworkPropertyMetadataOptions.AffectsMeasure, PropertyChangedCallback), ValidateStrokeThickness);
  ...
}

... and have that DependencyObject become a DependencyProperty of my UserControl:

public partial class ProjectListTreePanel : UserControl
{
  private static readonly DependencyProperty ArrowProperty = DependencyProperty.Register("Arrow", typeof(MyArrowProperties), typeof(ProjectListTreePanel), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure, PropertyChangedCallback));

Will changes to the properties of the MyArrowProperties DependencyObject be automatically forwarded to the containing ProjectListTreePanel UserControl, so MeasureOverride is getting called on the ProjectListTreePanel UserControl, when, for instance, I update

MyProjectListTreePanel.Arrow.StrokeThickness = 2

?

Or what do I need to do to have changes of encapsulated properties be forwarded to outer containers?

Similarity

The problem described here is similar to the Thickness struct. The Thickness struct is a collection of four distinct values. When any of these values changes, the Thickness struct raises an OnPropertyChanged event.

AxD
  • 2,714
  • 3
  • 31
  • 53
  • Probably not, but you could simply try it. Besides that, controls typically have many properties, so where is the point of your idea? – Clemens Aug 22 '21 at 14:23
  • I have a deep hierarchy of controls all sharing the same set of properties. I'd like to refrain from writing too much boiler plate code. On the other hand, I'm asking for a general rule of thumb. I was expecting this wouldn't work automatically. So, what's the suggested approach? Firing `OnPropertyChanged` for all the enclosed properties? – AxD Aug 23 '21 at 00:38

0 Answers0