繁体   English   中英

WPF应用程序和调度程序:使UI响应的问题

[英]WPF app and dispatcher: Issue with making UI responsive

我有一个使用Webbrowser控件的C#/ WPF应用程序。 我正在尝试使用Dispathcer从我的视图模型中设置DocumentPath的值。 但是我的UI变得无响应,直到WebBrowser控件完全加载文档为止。 我如何摆脱这个问题? 请指教。

这是我的代码: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">

视图模型:

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

}

尝试这个:

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

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

如果您不知道如何实现OnPropertyChanged,请在此处观看。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM