【问题标题】:How to create a WPF form containing a web-browser tool that(web-browser) can adjust it's size to fit it's Window如何创建一个包含 Web 浏览器工具的 WPF 表单,该工具(Web 浏览器)可以调整它的大小以适应它的窗口
【发布时间】:2017-06-02 13:33:51
【问题描述】:
我是 C# 和 Visual Studio 的新手。我正在使用 Visual Studio 2013 Express。我想在 C# 中创建一个 WPF 应用程序,其中应该有一个 Web 浏览器。我想要一个这种形式的网络浏览器,它可以根据窗口大小调整它的大小。
我搜索了很多次,但我没有找到我要找的东西。
注意:我不希望窗口调整其大小以适应其内容,我想要一个包含(Web-browser)的表单,它应该调整其大小作为表单拉伸的窗口。
【问题讨论】:
标签:
c#
wpf
visual-studio
xaml
【解决方案1】:
我猜你可以使用WebBrowser控件作为窗口的根元素,并将其Width和Height属性绑定到窗口的ActualWidth和ActualHeigth属性:
<Window x:Class="WpfApplication1.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"
xmlns:local="clr-namespace:WpfApplication4"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300"
x:Name="win">
<WebBrowser x:Name="wb" Source="http://google.com"
Width="{Binding ActualWidth, ElementName=win}"
Height="{Binding ActualHeight, ElementName=win}"/>
</Window>