views:

381

answers:

1

I am attempting to add a WPF usercontrol to an existing WinForms project and get the WPF UserControl to dock and fill the entire space.

There's a current framework that loads WinForms UserControls into a parent form (into a panel) in response to button clicks. This is where I'm trying to hook in - The WinForms UserControl that's currently getting loaded will have the ElementHost.

Hierarchy:

  • Form1.cs - contains a panel that gets WinForms UserControls dynamically loaded
    • WinForms UserControl - contains the ElementHost
      • WPF UserControl

The ElementHost has Dock set to Fill and its Child property set to ucReport, which is a WPF UserControl, which has the following markup (only top level design included):

<UserControl x:Class="MyClassName"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <TabControl HorizontalAlignment="Left" Name="tabControl1">
        <TabItem Header="Header1">
           ...The interesting stuff goes here
        </TabItem>
    </TabControl>
</UserControl>

The content of the UserControl does expand vertically when I resize the form, but horizontally, the content only expands large enough to accomodate its content.

When I view the WinForms UserControl (the one that has the ElementHost) in the designer, the problem is apparent. The WPF content that's specified is getting rendered and it's filled top to bottom, but not left to right.

I'm of the mind that it's something in the XAML that has to be set (perhaps on the UserControl declaration?) to get it to fill it's parent container, which is the ElementHost - I just can't find the property.

Would someone enlighten me?

+1  A: 

Change HorizontalAlignment to Stretch or get rid of it entirely.

Paul Betts
For heaven's sake. Of course. Thank you.
Paul Prewett