views:

217

answers:

2

Here is the code that cause me problem since few hours:

        TabItem newTab = new TabItem();
        newTab.Header = source.Name;
        newTab.Content = source.GetGui();
        newTab.HorizontalContentAlignment = HorizontalAlignment.Stretch;
        newTab.VerticalContentAlignment = VerticalAlignment.Stretch;
        this.inputSourceDisplay.Items.Add(newTab);

The output is the control (from GetGui()) is showing but in the center vertical and in the center horizontal but haven't stretch at it suppose.

How can I solve that or how can I debug that?

A: 

In WPF if the user control has a default width or height, the user control won't strech even if you use the Enumeration for stretching.

The solution was to remove from the UserControl Xaml the default width and height and the control behaved the way it should.

Daok
+1  A: 

What does your "GetGui()" method return? Is it a UserControl? By default, UserControls explicitly set their Width and Height properties:

<UserControl x:Class="WpfApplication1.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">

With the Height and Width explicitly set, the UserControl won't respond to attributes like HorizontalContentAlignment.

Matt Hamilton
Thanks, I just figure out at the same time your posted this post.
Daok
haha yeah - beat me by seconds! Oh well, thanks for the answer acceptance.
Matt Hamilton