我想将Windows窗体控件包装在wpf UserControl中
<UserControl x:Class="MVVMLibrary.ReportViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ws="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Height="Auto" Width="Auto">
<Grid>
<WindowsFormsHost Name="Host">
<ws:ReportViewer/>
</WindowsFormsHost>
</Grid>
</UserControl>
请注意,高度和宽度是自动的。
当我将其放置在堆栈面板或网格控件中时,它将其高度设置为0,并且基本上消失了。然后,要求用户调整窗口的大小(缩小,因为用户控件说我不需要任何空间,谢谢)。当用户调整大小时,它会扩展到用户指定的大小。
所以我的问题是我做错了什么?如何使我的用户控件占用所有可用空间,而不是不要求任何空间?
最佳答案
我找到一个更好的答案。
使用带有LastChildFill = true的dockPanel,然后将其与Strech进行水平和垂直对齐,然后放入WindowsFormsHost中,当然必须填充WindowsForms控件。
<DockPanel LastChildFill="true">
<WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Panel Dock=Fill />
</WindowsFormsHost>
</DockPanel>
请享用',
关于wpf - WPF WindowsFormsHost大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/977729/