Question

For some reason, I can't get my Winform usercontrol to fit inside of the WindowsFormsHost. Here's the xaml that I am using:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="326*" />
    <ColumnDefinition Width="300*" />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="264*" />
    <RowDefinition Height="100*" />
    <RowDefinition Height="50*" />
  </Grid.RowDefinitions>
  <WindowsFormsHost   Grid.Row="1"
                      Grid.Column="0">
    <winforms:ServicesUserControl x:Name="servicesUserControl"
                                  UserCanEditRevenue="True"
                                  BorderStyle="Fixed3D">
    </winforms:ServicesUserControl>
  </WindowsFormsHost>
</Grid>

Here's a screenshot to show what I mean:

Here is the original user control: enter image description here

But when I put it in a WindowsFormHost I get this: enter image description here

Was it helpful?

Solution

Unless the UserControl has its own logic to resize the columns, the width of the UserControl will be bound to the width of its columns. I would try implementing the WinFormsHost inside a ScrollViewer, if that will be an acceptable layout.

<ScrollViewer Grid.Row="1"
              Grid.Column="0">
  <WindowsFormsHost>
    <winforms:ServicesUserControl x:Name="servicesUserControl"
                                  UserCanEditRevenue="True"
                                  BorderStyle="Fixed3D" />
  </WindowsFormsHost>
</ScrollViewer>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top