Reputation: 4359
I have a winforms custom control that I'm attempting to host in a WindowsFormControl. I seem be running into some issues getting the height of the control to behave correctly.
I've got a grid, that contains a StackPanel, which contains the actual embedded WindowsFormControl. I would like the WindowsFormControl's height to take up all the available height in the StackPanel.
The actual winforms custom user control's height behaves correctly as it fills the height area available within the WindowsFormHost.
I'm not entirely clear on what's going on.
Grid Grid.Row="0" Background="#7A66BAD2">
<Grid.RowDefinitions>
<RowDefinition Height="9*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" >
<WindowsFormsHost Name="RPIWinformsHost" Height="700"
Background="Orange"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="30,10,30,10">
<rpiRTFControl:RPIReportDesignControl Name="RPIRTFControl" />
</WindowsFormsHost>
</StackPanel>
<Border BorderBrush="#CCCCFF" Grid.Row="1" BorderThickness="6"
HorizontalAlignment="Stretch" Margin="30,0,30,0">
<StackPanel Name="spCommands"
Orientation="Horizontal">
<Button Name="btnTest" Content="Test" Height="25" Width="134"
FontSize="13" FontWeight="Bold"
Margin="10,0,10,0"
Click="btnTest_Click" />
</StackPanel>
</Border>
</Grid>
What is the correct technique/trick for having this behave correctly?
Thanks, JohnB
Upvotes: 0
Views: 151
Reputation: 12670
StackPanel isn't meant to be used that way, it's generally for a series of auto-sized items where you don't know how many there will be until run time. Just remove the StackPanel and let the WindowsFormsHost live directly under the Grid.
<WindowsFormsHost Name="RPIWinformsHost" Height="700" Grid.Row="0"
Background="Orange"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="30,10,30,10">
<rpiRTFControl:RPIReportDesignControl Name="RPIRTFControl" />
</WindowsFormsHost>
Upvotes: 1