October 15, 2014 1 Comment
If you create a custom control that derives from FrameworkElement, the control won’t by default have any particular desired size. You can see this by setting alignment properties on a simple custom control without also setting explicit Width and Height.
<Grid ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <loc:MyFrameworkElement HorizontalAlignment="Center" VerticalAlignment="Top"/> <loc:MyFrameworkElement Grid.Row="1" Margin="20,10"/> </Grid>
You can see in the designer that the first instance of MyFrameworkElement is not visible, because it has no size.
A custom control will typically define its desired size based on its content. In the example above, the custom control hasn’t specified any desired size, size the control has a size of (0,0) and disappears.