C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Name: This WPF attribute will be automatically turned into a property in the C# code for the window. We use "MainBrowser".
NameExample markup: XAML
<Window x:Class="WpfApplication28.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded">
<Grid>
<WebBrowser HorizontalAlignment="Left"
Height="299"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="497"
Name="MainBrowser"/>
</Grid>
</Window>
Example code: C#
using System.Windows;
namespace WpfApplication28
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// ... Load this site.
this.MainBrowser.Navigate("http://en.wikipedia.org/");
}
}
}
Here: Please make sure to place the HTML file in a directory on your computer. Adjust the file URI to point to the file.
Example file: HTML
<h1>Hi there!</h2>
<p>
file.html
</p>
Example code: C#
using System.Windows;
namespace WpfApplication28
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// ... Load a local HTML page.
this.MainBrowser.Navigate("file:///C:/folder/file.html");
}
}
}
Tip: Please use the CanGoBack and CanGoForward properties before calling GoBack and GoForward. This will eliminate exceptions.
Bool