wpf里窗体嵌入winform控件被覆盖问题
问题1:嵌套Winform控件(ZedGraph)在WPF的ScrollViewer控件上,出现滚动条,无论如何设置该Winform控件都在顶层,滚动滚动条会覆盖其他WPF控件。
解决办法:在ScrollViewer上嵌套一层ElementHost,其作用相当于将ScrollViewer整一层又包装成Winform。
<wfi:WindowsFormsHost><wfi:ElementHost><ScrollViewer /> </wfi:ElementHost></wfi:WindowsFormsHost>
如:
<UserControl x:Class="AnesMS.TakeManage.AnesPrintView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:zedgraph="clr-namespace:ZedGraph;assembly=ZedGraph"
xmlns:GraphCtrl="clr-namespace:DIH.ORIMS.GraphControl;assembly=DIH.ORIMS.GraphControl"
mc:Ignorable="d"
x:Name="UserControl"
d:DesignHeight="550" d:DesignWidth="1250">
<Grid Width="1024" Height="650">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Label Content="打印预览" Style="{StaticResource PopBannerStyle}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
<wfi:WindowsFormsHost Grid.Row="1">
<wfi:ElementHost>
<ScrollViewer Grid.Row="1" Panel.ZIndex="0">
如:
<UserControl x:Class="AnesMS.TakeManage.AnesPrintView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:zedgraph="clr-namespace:ZedGraph;assembly=ZedGraph"
xmlns:GraphCtrl="clr-namespace:DIH.ORIMS.GraphControl;assembly=DIH.ORIMS.GraphControl"
mc:Ignorable="d"
x:Name="UserControl"
d:DesignHeight="550" d:DesignWidth="1250">
<Grid Width="1024" Height="650">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Label Content="打印预览" Style="{StaticResource PopBannerStyle}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
<wfi:WindowsFormsHost Grid.Row="1">
<wfi:ElementHost>
<ScrollViewer Grid.Row="1" Panel.ZIndex="0">
<wfi:WindowsFormsHost x:Name="winFormPrint" Width="760" Height="1080" Panel.ZIndex="-1">
<GraphCtrl:GraphCtrl x:Name="graphCtrl" />
</wfi:WindowsFormsHost>
</ScrollViewer>
</wfi:ElementHost>
</wfi:WindowsFormsHost>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<Button Command="{Binding CancelCommand}" Style="{StaticResource LightGreenButton}" Content="关闭" HorizontalAlignment="Right" Margin="0,0,20,0" Name="button1" VerticalAlignment="Bottom" Width="75" Grid.Row="1" Height="37" />
<Button IsEnabled="False" Content="打印" Height="37" HorizontalAlignment="Right" Margin="0,0,0,0" Name="button2" Style="{StaticResource LightGreenButton}" VerticalAlignment="Bottom" Width="75" Grid.Row="1" />
</StackPanel>
</Grid>
</UserControl>
<GraphCtrl:GraphCtrl x:Name="graphCtrl" />
</wfi:WindowsFormsHost>
</ScrollViewer>
</wfi:ElementHost>
</wfi:WindowsFormsHost>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<Button Command="{Binding CancelCommand}" Style="{StaticResource LightGreenButton}" Content="关闭" HorizontalAlignment="Right" Margin="0,0,20,0" Name="button1" VerticalAlignment="Bottom" Width="75" Grid.Row="1" Height="37" />
<Button IsEnabled="False" Content="打印" Height="37" HorizontalAlignment="Right" Margin="0,0,0,0" Name="button2" Style="{StaticResource LightGreenButton}" VerticalAlignment="Bottom" Width="75" Grid.Row="1" />
</StackPanel>
</Grid>
</UserControl>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器