RSS

WPF Controls do not resize inside container

19 Oct

When you try to put a WPF User Control or a Page inside of a container you will notice the control is not resizing to the parent it is hosted in. Example, a page that is hosted in a frame.

This is due to the size you have set to the control or page.

 <Page x:Class=”LAD_Project_Planning_WPF.pProjectCard” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”  Title=”pProjectCard” Loaded=”Page_Loaded” Height=”382″ Width=”789″>
<Page.Resources>

 

As you can see the page’s height and width are set to 382 and 789 pixels. This will cause the control to always have these dimensions. It doesn’t matter if it is set to strech inside of a container or not.

Removing the dimensions from the control will solve this issue at runtime, but you won’t be able to see the control in design time.

The only solution I found until now was to change the dimensions in the OnLoad event.

if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
    this.Width = double.NaN; 
    this.Height = double.NaN;
}

 
1 Comment

Posted by on October 19, 2009 in .NET

 

Tags: ,

One Response to WPF Controls do not resize inside container

  1. D

    March 26, 2011 at 03:14

    use d:DesignHeight and Width

     

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.