0

Before you guys say that this is a duplicate request, please hear me out. I've tried the solutions mentioned in the questions like below:

WPF Web Browser Control

But it didn't work for me as in, instead of displaying a web page, it displays the url as plain text.

Here's my code:

xmlns:resources="clr-namespace:MyApplication.Resources"

<Grid> <WebBrowser resources:WebBrowserUtility.BindableSource="{Binding ReportPage}"/> </Grid>

public static class WebBrowserUtility
{
    public static readonly DependencyProperty BindableSourceProperty =
                      DependencyProperty.RegisterAttached("BindableSource", typeof(string),
                      typeof(WebBrowserUtility), new UIPropertyMetadata(null,
                      BindableSourcePropertyChanged));

    public static string GetBindableSource(DependencyObject obj)
    {
        return (string)obj.GetValue(BindableSourceProperty);
    }

    public static void SetBindableSource(DependencyObject obj, string value)
    {
        obj.SetValue(BindableSourceProperty, value);
    }

    public static void BindableSourcePropertyChanged(DependencyObject o,
                                                     DependencyPropertyChangedEventArgs e)
    {
        var webBrowser = (WebBrowser)o;
        if(webBrowser != null)
        {
            string uri = e.NewValue as string;
            webBrowser.Source = !String.IsNullOrEmpty(uri) ? new Uri(uri) : null;
        }

    }
}

public class ReportViewModel: ViewModelBase
{

    public ReportViewModel()
    {
        ReportPage = new Uri(@"https://www.google.com");
    }
    private Uri _reportPage;
    public Uri ReportPage
    {
        get
        {
            return _reportPage;
        }

        set
        {
            if (_reportPage != value)
            {
                _reportPage = value;
                OnPropertyChanged("ReportPage");
            }
        }
    }
}

But, in the view, instead of actually opening the "google" website, it just displays the URI: https://www.google.com.

Community
  • 1
  • 1
Abhijith
  • 69
  • 1
  • 10

0 Answers0