如何在同一个窗口中显示windowsformshost控件和wpf网格?

时间:2015-03-17 11:48:20

标签: c# wpf windowsformshost

我使用WindowsFormsHost控件在我有网格控件的同一窗口中查看pdf文档。当windowsformshost可见时,现在网格不可见。我需要同时显示两个控件。

请任何人帮我一起显示两个控件。

这是我的代码

   ViewDocument doc = new ViewDocument("Hide", "R1B", "", "Chapters", "");
            doc.windowsFormsHost1.Visibility = Visibility.Visible;
            var uc = new Pdfdocument(quespath);
            doc.windowsFormsHost1.Child = uc;
            doc.Show();

    if (fmtyp == "Hide")
        {
            transgrid.Visibility = Visibility.Visible;
        }

XAML代码 -

<Canvas Grid.ColumnSpan="9" Grid.RowSpan="6" Margin="3,0,0,1" Name="canvas1" Grid.Column="5" Grid.Row="6">
        <WindowsFormsHost Name="windowsFormsHost1" Visibility="Hidden" Canvas.Left="6" Canvas.Top="0" Height="557" Width="881" />
        <Grid Name="transgrid" Canvas.Left="6" Canvas.Top="0" Height="557" Width="875">
            <Grid.Background>
                <ImageBrush ImageSource="/RaptorHscIIBlueprint;component/Images/1409934598_Help.png" />
            </Grid.Background>
        </Grid>
 </Canvas>

1 个答案:

答案 0 :(得分:0)

您的控件位于彼此之上 - 试试这个 -

<StackPanel Grid.ColumnSpan="9" Grid.RowSpan="6" Margin="3,0,0,1" Name="stackPanel1" Grid.Column="5" Grid.Row="6">
    <WindowsFormsHost Name="windowsFormsHost1" Visibility="Hidden" Height="557" Width="881" />
    <Grid Name="transgrid" Height="557" Width="875">
        <Grid.Background>
            <ImageBrush ImageSource="/RaptorHscIIBlueprint;component/Images/1409934598_Help.png" />
        </Grid.Background>
    </Grid>