Problem: Show a website in a WebBrowser (or similar control), The original site has a login page that guides you to a statement selection page, once you select a store and date selecting "submit" opens another page that shows a table of invoices. The HTML of the table has the ID of "statement".
My ultimate goal is to get the table and parse the rows for the data.
I tried adding the WebBrowser control in the View, setting the source to the site. This worked and I was able to login, select the location and view the statement page. However I could not find a way bind the HTML in the WebBrowser control to a variable in the ViewModel.
<Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Grid.Row="2">
<WebBrowser Source="www.google.com" />
</Border>
Also the "source" is not bind able if I want to be able to change this in the future with a drop box.
Next idea is to create a WebBrowser object in the ViewModel, assign the web site to the source of the WebBrowser and bind the WebBrowser in the View to the WebBrowser in the ViewModel.
WebBrowser of the ViewModel (2nd attempt) I changed the website for security:
<Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Grid.Row="2">
<WebBrowser DataContext="{Binding StatementSite}"/>
</Border>
ViewModel Code:
private WebBrowser _statementSite = new WebBrowser();
public WebBrowser StatementSite
{
get { return _statementSite; }
set {
_statementSite = value;
NotifyOfPropertyChange(() => StatementSite);
}
}
public void StartProgressCommand()
{
StatementSite.Source = new Uri("https://www.google.com/");
NotifyOfPropertyChange(() => StatementSite);
}
When I run the program this way it compiles and starts with no errors but there is no site visible in the view, just a black control. The original way below shows the site perfect but I can not find a way to bind the HTML to a property in the ViewModel.
<Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Grid.Row="2">
<WebBrowser Source="http:\\www.google.com"/>
</Border>
Is the WebBrowser control even a good way to accomplish this? And how can I bind the HTML to the ViewModel or Build the WebBrowser control in the ViewModel and have it show in the view?