Minato Namikaze Minato Namikaze - 1 month ago 8
Vb.net Question

How to display the url of navigated page in web browser VB.NET WPF

I am making a web browser in VB.Net in WPF. I want to show the URL of current page in a text block. I am unable to do so. There is no URL property in WPF as it is in WinForms. There is UID property but I don't understand what it is for. There is a SOURCE property again I couldn't get what it does.
As I navigate ahead the URL of that page should be displayed.

For example, I am on google so address bar(which is the text block) should show the URL of GOOGLE when I navigate to YOUTUBE from GOOGLE, so URL should change as per my navigation.

Help PLease. I have less time.

mm8 mm8
Answer Source

Handle the SourceUpdated and Navigated events and set the Text property of the TextBlock to the AbsoluteUri of the Uri:

private void wb_SourceUpdated(object sender, DataTransferEventArgs e)
    WebBrowser wb = sender as WebBrowser;
    textBlock.Text = wb.Source.AbsoluteUri;

private void wb_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
    WebBrowser wb = sender as WebBrowser;
    textBlock.Text = e.Uri.AbsoluteUri;