WPF——WebBroswer无法显示问题

来源:互联网 发布:e=mc2知乎 编辑:程序博客网 时间:2024/06/03 19:16

在WPF中Window里面放置WebBroswer控件居然无法显示:

源代码如下:

<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>
        <WebBrowser Name="broswer"                    Grid.Row="1"/>    </Grid></Window>

显示效果:



经过折腾和尝试,问题出在Window里面的AllowsTransparency属性,WebBroswer控件显示和AllowsTransparency为True时产生冲突。

去掉AllowsTransparency后显示效果如下:



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


原创粉丝点击