Winform UserControl and wpf WindowsFormHost: UserControl goes off the edge of the WindowsFormHost

StackOverflow https://stackoverflow.com/questions/13653100

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

Était-ce utile?

La 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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top