Varun Rajput
Varun Rajput

Reputation: 63

How to create a WPF form containing a web-browser tool that(web-browser) can adjust it's size to fit it's Window

I am new to C# and Visual Studio. I am using Visual Studio 2013 Express. I want to create a WPF application in C# that should has a web-browser in it. I want a web-browser in that form that can adjust it's size depending on the Window size. I searched many times but I didn't found for what I'm looking for. Note: I don't want a Window adjusting its size to fit its contents rather, I want a form containing(Web-browser) and it should adjust its size as Window of form stretched.

Upvotes: 1

Views: 294

Answers (1)

mm8
mm8

Reputation: 169190

I guess you could use the WebBrowser control as the root element of the window and bind its Width and Height properties to the ActualWidth and ActualHeigth properties of the window:

<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>

Upvotes: 1

Related Questions