簡體   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