0

I've a C#/WPF app in which I'm using a webbrowser control. I'm trying to set the value of DocumentPath from within my view model using Dispathcer. But my UI gets becomes unresponsive until the WebBrowser control loads the document completely. How can I get rid of this issue ? Please advise.

Here's my code: Xaml:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      
    xmlns:viewModel="clr-namespace:MVMs.ViewModel"
>
<Window.DataContext>
        <viewModel:MyViewModel/>
    </Window.DataContext>


<WebBrowser x:Name="MyWebBrowser1" 
            myVM:WebBrowserExtensions.BindableSource="{Binding DocumentPath}"
 VerticalAlignment="Stretch" Margin="0,0,0,-11">

ViewModel:

public MyViewModel()
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(
 DispatcherPriority.Background,
                   new Action(DocumentPath="myDocPath"));

}
Jimmy
  • 2,106
  • 12
  • 39
  • 53
  • You're doing MVVM, why do you need to use a background thread? Just set it via property and raise property changed – Tyress Feb 01 '17 at 02:05

1 Answers1

0

Try this:

private string _DocumentPath;
public string DocumentPath
{
    get { return _DocumentPath; }
    set
    {
        _DocumentPath = value;
        OnPropertyChanged("DocumentPath");
    }
}

public MyViewModel()
{
    DocumentPath = "myDocPath";
}

If you don't know how to implement OnPropertyChanged watch here.

Community
  • 1
  • 1
remarkies
  • 113
  • 10