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

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

문제

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

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top