#1,180 – By Default, FrameworkElement Doesn’t Have Desired Size

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">

        <loc:MyFrameworkElement HorizontalAlignment="Center"
        <loc:MyFrameworkElement Grid.Row="1" Margin="20,10"/>

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.



About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,180 – By Default, FrameworkElement Doesn’t Have Desired Size

  1. Pingback: Dew Drop – October 15, 2014 (#1877) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: