I need to add WebBrowser control to WPF form.
I have the easiest code:
<Window x:Class="WpfApplication2.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="279" Margin="10,10,0,0" Name="wb1" VerticalAlignment="Top" Width="461">
</WebBrowser>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string url = "http://www.microsoft.com";
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
wb1.Source = new Uri(url);
}
}
}
but application is closing automatically navigate to page. Why?
I see the following strings on output code:
The program '[4892] WpfApplication5.vshost.exe: Program Trace' has exited with code 0 (0x0). The program '[4892] WpfApplication5.vshost.exe: Managed (v4.0.30319)' has exited with code -1073740791 (0xc0000409).
I fixed this problem (but only for Visual Studio 2010, project under Visual Studio 2013 has error) - I have changed "Target Platform" from x86 to "Any CPU". Strange, but works
User contributions licensed under CC BY-SA 3.0