tags:

views:

57

answers:

2

I'm making a UserControl that is a child of a StackPanel. When it's content changes the size of the control should also change. How should the UserControl notify the StackPanel (or any other container control) that it's size has changed?

For example, if you have a Label control and change the Content element then it will be resized. How does it do this?

A: 

Call InvalidateMeasure(). This causes the StackPanel (or other container control) to recalculate its layout.

dan gibson
A: 

Also, in addition to InvalidateMeasure, if the change in size is the result of a dependency property change you can set the FrameworkPropertyMetadata.AffectsMeasure flag:

public static DependencyProperty ToolbarProperty =
            DependencyProperty.Register("Toolbar", typeof(UIElement),
            typeof(EditorWindow), 
            new FrameworkPropertyMetadata(null,FrameworkPropertyMetadataOptions.AffectsArrange|
            FrameworkPropertyMetadataOptions.AffectsMeasure|FrameworkPropertyMetadataOptions.AffectsRender));
Nir