WPF——WebBroswer无法显示问题

在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后显示效果如下:



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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值