欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

WPF——WebBroswer无法显示问题

程序员文章站 2022-09-02 21:49:47
view plaincopyprint?   在WPF中Window里面放置WebBroswer控件居然无法显示: 源代码如下: [html]

view plaincopyprint?
 
WPF中Window里面放置WebBroswer控件居然无法显示:
源代码如下:
[html]
<Window x:Class="MutilScreenDemo.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        Title="MainWindow" 
        AllowsTransparency="True" 
        Background="Black" 
        BorderBrush="Transparent" 
        BorderThickness="0" 
        d:DesignHeight="348" 
        d:DesignWidth="892" 
        Loaded="Window_Loaded" 
        ResizeMode="NoResize" 
        WindowStyle="None" 
        mc:Ignorable="d"> 
 
    <Grid x:Name="layoutRoot"> 
        <Grid.RowDefinitions> 
            <RowDefinition Height="100" /> 
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <Rectangle Height="2" 
                   VerticalAlignment="Bottom" 
                   Fill="White" /> 
        <TextBlock Name="txtShow" 
                   Grid.Row="0" 
                   HorizontalAlignment="Left" 
                   VerticalAlignment="Center" 
                   FontSize="50" 
                   FontWeight="Bold" 
                   Foreground="Red" 
                   Text="Hello World!" /> 
        <StackPanel Grid.Row="0" 
                    HorizontalAlignment="Right" 
                    VerticalAlignment="Center" 
                    Orientation="Horizontal"> 
            <Button Name="button1" 
                    Margin="5" 
                    HorizontalAlignment="Right" 
                    VerticalAlignment="Top" 
                    Click="button1_Click" 
                    Content="Get Screen Info" 
                    Padding="20" /> 
            <Button Name="btnShutdown" 
                    Margin="5" 
                    HorizontalAlignment="Right" 
                    VerticalAlignment="Top" 
                    Click="btnShutdown_Click" 
                    Content="ShutDown App" 
                    Padding="20" /> 
        </StackPanel> 
[html]
 
[html]
    <WebBrowser Name="broswer" 
                Grid.Row="1"/> 
</Grid> 
/Window> 

显示效果:

WPF——WebBroswer无法显示问题
经过折腾和尝试,问题出在Window里面的AllowsTransparency属性,WebBroswer控件显示和AllowsTransparency为True时产生冲突。
去掉AllowsTransparency后显示效果如下:
WPF——WebBroswer无法显示问题


但是具体问什么会这样,我没搞清楚。希望有大神指点一二!!