I am creating the custom control where i need to update the layout if one of the Dependency property changes. I can use the FrameworkMetadataProperty.AffectsMeasure
or FrameworkMetadataProperty.AffectsArrange
.
Q.1 - I am confused which one to use.
Moreover I can also use the UpdateLayout and InvalidateVisual methods as well in order to update the UI.
Q.2 - All these 4 things looks similar and am confused on which one to use when?
First, the difference between setting FrameworkPropertyMetadataOptions and calling methods as UpdateLayout or InvalidateVisual is obvious. In the latter case you call these methods in your control code, wheras in the former case the appropriate methods are called by the framework.
The difference between
AffectsMeasure
andAffectsArrange
is simply that one results in a call to UIElement.InvalidateMeasure ("affects the measure pass of the layout") and the other results in a call to UIElement.InvalidateArrange ("affects the arrange pass of the layout").The difference becomes clear from the Remarks in UIElement.Measure:
and from the Remarks in UIElement.InvalidateMeasure:
UPDATE: For the difference between UpdateLayout and InvalidateVisual, see the Remarks in UpdateLayout:
and in InvalidateVisual: