Winform UserControl和wpf WindowsFormsHost:UserControl不在WindowsFormsHost的边缘

时间:2012-11-30 20:59:34

标签: c# .net wpf xaml windowsformshost

出于某种原因,我无法让Winform usercontrol适合WindowsFormsHost。这是我正在使用的xaml:

<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>

这是一个屏幕截图,显示我的意思:

这是原始用户控件: enter image description here

但是当我把它放在WindowsFormHost中时,我得到了这个: enter image description here

1 个答案:

答案 0 :(得分:0)

除非UserControl有自己的逻辑来调整列的大小,否则UserControl的宽度将绑定到其列的宽度。我会尝试在ScrollViewer中实现WinFormsHost,如果这将是一个可接受的布局。

<ScrollViewer Grid.Row="1"
              Grid.Column="0">
  <WindowsFormsHost>
    <winforms:ServicesUserControl x:Name="servicesUserControl"
                                  UserCanEditRevenue="True"
                                  BorderStyle="Fixed3D" />
  </WindowsFormsHost>
</ScrollViewer>