wpf里窗体嵌入winform控件被覆盖问题
问题1:嵌套Winform控件(ZedGraph)在WPF的ScrollViewer控件上,出现滚动条,无论如何设置该Winform控件都在顶层,滚动滚动条会覆盖其他WPF控件。
如:
View Code
解决办法:在ScrollViewer上嵌套一层ElementHost,其作用相当于将ScrollViewer整一层又包装成Winform。
<wfi:WindowsFormsHost> <wfi:ElementHost> <ScrollViewer /> </wfi:ElementHost> </wfi:WindowsFormsHost>
如:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <UserControl x:Class="AnesMS.TakeManage.AnesPrintView" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 6 xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" 7 xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 8 xmlns:zedgraph="clr-namespace:ZedGraph;assembly=ZedGraph" 9 xmlns:GraphCtrl="clr-namespace:DIH.ORIMS.GraphControl;assembly=DIH.ORIMS.GraphControl" 10 mc:Ignorable="d" 11 x:Name="UserControl" 12 d:DesignHeight="550" d:DesignWidth="1250"> 13 14 15 <Grid Width="1024" Height="650"> 16 <Grid.RowDefinitions> 17 <RowDefinition Height="40" /> 18 <RowDefinition Height="*" /> 19 <RowDefinition Height="50" /> 20 </Grid.RowDefinitions> 21 <Label Content="打印预览" Style="{StaticResource PopBannerStyle}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/> 22 <wfi:WindowsFormsHost Grid.Row="1"> 23 <wfi:ElementHost> 24 <ScrollViewer Grid.Row="1" Panel.ZIndex="0"> 25 <wfi:WindowsFormsHost x:Name="winFormPrint" Width="760" Height="1080" Panel.ZIndex="-1"> 26 <GraphCtrl:GraphCtrl x:Name="graphCtrl" /> 27 </wfi:WindowsFormsHost> 28 </ScrollViewer> 29 </wfi:ElementHost> 30 </wfi:WindowsFormsHost> 31 <StackPanel Orientation="Horizontal" Grid.Row="2"> 32 <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" /> 33 <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" /> 34 </StackPanel> 35 </Grid> 36 </UserControl>