November 4, 2014 1 Comment
After the measure phase, during which a custom element calls the Measure method on each of its child elements, each child element will set its DesiredSize property to indicate how much space it wants.
The DesiredSize of a child element accounts for any margins that have been set on that child. Assume that we have the following XAML (MyElement is a custom element with a single child).
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <loc:MyElement x:Name="Left"> <loc:MyElement.Child> <Label Content="Doowahditty"/> </loc:MyElement.Child> </loc:MyElement> <loc:MyElement Grid.Column="1" x:Name="Right"> <loc:MyElement.Child> <Label Content="Doowahditty" Margin="10"/> </loc:MyElement.Child> </loc:MyElement> </Grid>
We can look at the value of the DesiredSize property after Measure has been called on the child element. We can see that in the second case, the desired size is larger, indicating that the child wants to add a margin.