Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF浏览器在那里,但不可见_Wpf_Wpf Controls - Fatal编程技术网

WPF浏览器在那里,但不可见

WPF浏览器在那里,但不可见,wpf,wpf-controls,Wpf,Wpf Controls,我正试图在一个非常简单的WPF应用程序中使用浏览器控件,当浏览器加载我请求的页面时(我可以将鼠标移到图像上并查看ALT标记),我实际上看不到任何其他内容: 以下是应用程序的XAML: <Window x:Class="SmokeyBox2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsof

我正试图在一个非常简单的WPF应用程序中使用浏览器控件,当浏览器加载我请求的页面时(我可以将鼠标移到图像上并查看ALT标记),我实际上看不到任何其他内容:

以下是应用程序的XAML:

<Window x:Class="SmokeyBox2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SmokeyBox" Height="120" Width="510" ShowInTaskbar="False"
        SizeToContent="WidthAndHeight" WindowStyle="None" AllowsTransparency="True"
        MouseLeftButtonDown="Window_MouseLeftButtonDown">
    <Border Background="#50FFFFFF" CornerRadius="5" BorderThickness="2,0,2,2"
            Padding="5 1 5 5">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Background="Transparent"  Content="SmokeyBox" 
                   MouseLeftButtonDown="Label_MouseLeftButtonDown" />
            <TextBox Grid.Row="1" Grid.Column="0" Name="searchText" Width="450" FontFamily="Arial" Foreground="DarkGray"
                     Background="Transparent" FontSize="20" MouseLeftButtonDown="searchText_MouseLeftButtonDown"
                     BorderBrush="Transparent" />
            <Expander Grid.Row="1" Grid.Column="1" Padding="2 3 0 0 " Expanded="Expander_Expanded"
                      Collapsed="Expander_Collapsed" />
            <WebBrowser Grid.Row="2" Grid.Column="0" x:Name="browser" Visibility="Visible"
                        Width="480" Height="480" Margin="2 2 2 2" ></WebBrowser>
        </Grid>
    </Border>
</Window>

那么有谁能帮我弄清楚为什么浏览器没有显示Yahoo!主页像我要求的那样?在我做这件事的时候,我要承认这是我的第一个WPF应用程序,我很想听到关于如何在我的XAML中摆脱noobie的坏习惯的一般性的建议


谢谢。

只是一个简短的回复,不幸的是,迟到了


您需要设置AllowTransparency=“False”:

您是否正在设置
WebBrowser.Source
属性?我在Kaxaml中尝试了以下XAML,效果很好:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Border>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="SmokeyBox" />
                <TextBox Grid.Row="1" Grid.Column="0" Name="searchText" FontFamily="Arial" Foreground="DarkGray"
                         Background="Transparent" FontSize="20" BorderBrush="Transparent" />
                <Expander Grid.Row="1" Grid.Column="1" Padding="2 3 0 0" />
                <WebBrowser Source="http://www.yahoo.com" Grid.Row="2" Grid.Column="0" x:Name="browser" Visibility="Visible"
                            Margin="2 2 2 2" />
            </Grid>
        </Border>
    </Page>
您可能希望浏览并更新页边距,使其看起来像您希望的那样


此外,从您的屏幕截图可以清楚地看到,由于XAML与图像中的内容不匹配,您在这里有一些额外的样式/模板。可能来自这些样式的值正在干扰您的控件。

WPF WebBrowser无法使用AllowTransparency=“True”。

我刚刚找到了一个解决方案。基本上,它只是显示另一个窗口上的网络控制应该是。。。这有点脏,但效果很好:)

这是一个老问题,但我想发布我为让它工作所做的工作

当您想要创建一个没有边框的窗口,该窗口可以调整大小,并且能够承载指向URL的WebBrowser控件或框架控件,而您根本无法创建URL时,所述控件的内容将显示为空,如OP所述

我找到了一个解决办法;在窗口中,如果您将WindowsStyle设置为None,将ResizeMode调整为NoResize(恕我直言,完成后您仍然可以调整大小),然后确保取消选中AllowTransparency,您将有一个静态大小的窗口,没有边框,并将显示浏览器控件

现在,您可能仍然希望能够调整大小,对吗?我们可以通过互操作调用:

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    //Attach this to the MouseDown event of your drag control to move the window in place of the title bar
    private void WindowDrag(object sender, MouseButtonEventArgs e) // MouseDown
    {
        ReleaseCapture();
        SendMessage(new WindowInteropHelper(this).Handle,
            0xA1, (IntPtr)0x2, (IntPtr)0);
    }

    //Attach this to the PreviewMousLeftButtonDown event of the grip control in the lower right corner of the form to resize the window
    private void WindowResize(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        HwndSource hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)61448, IntPtr.Zero);
    }

瞧,这是一个WPF窗口,没有边框,仍然可以移动和调整大小,而且不会丢失与WebBrowser等控件的兼容性。我遇到了同样的问题,找到了这篇文章。没有人澄清标记为正确的答案。我还没有要点简单地发表评论。AllowTransparency=“False”需要应用于XAML窗口标记。例如:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WebBrowserControlSample.MainWindow"
Title="WebBrowser Control Sample"
MinHeight="200" MinWidth="200"
Height="600" Width="800"
WindowStartupLocation="CenterScreen" Background="LightSteelBlue"
AllowsTransparency="False">


这需要一些挖掘和调查才能弄清楚,但通过设置,我的隐形浏览器控件问题得到了缓解。

完全正确。非常感谢。但太糟糕了,因为透明度真的很漂亮。WebBrowser控件没有AllowTransparency属性。。。我在这里遗漏了什么?@DeanKuga你需要在你的窗口上设置这个属性,而不是在你的组件上。我希望这有帮助为什么窗口透明度会影响webbrowser控件?答案很好。非常感谢大家对WPF的更多细节的帮助。我越来越清楚,WPF的表面下有很多微妙之处和艺术。@Adam,别担心。透明度太差了。我注意到,在Kaxaml中,浏览器似乎漂浮在其余元素之上。毫无疑问,它得到了特殊的处理,并叠加在UI的其余部分之上。非常酷,Thomas。谢谢你的提示。我将尝试实现这个解决方案。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WebBrowserControlSample.MainWindow"
Title="WebBrowser Control Sample"
MinHeight="200" MinWidth="200"
Height="600" Width="800"
WindowStartupLocation="CenterScreen" Background="LightSteelBlue"
AllowsTransparency="False">