我在第一個視圖(MainView)中選擇一個文件並導入它,在第二個視圖(BView)中顯示該文件在數據網格中的詳細信息。在新任務中打開另一個視圖WPF caliburn.micro c#
這是第一個觀點(的MainView):
這是第二個觀點(BView):我想,當我點擊 「導入」 就出現
進度條和文本,而第二個視圖加載。我想打開另一個任務中的另一個視圖,但我收到此錯誤消息:
「調用線程無法訪問此對象,因爲不同的線程擁有它。」
這是MainViewModel的代碼是:
[Export(typeof(IShell))]
public class MainViewModel : Screen
{
public string Path{ get; set; }
public bool IsBusy { get; set; }
public string Text { get; set; }
[Import]
IWindowManager WindowManager { get; set; }
public MainViewModel()
{
IsBusy = false;
Text = "";
}
public void Open()
{
OpenFileDialog fd = new OpenFileDialog();
fd.Filter = "Text|*.txt|All|*.*";
fd.FilterIndex = 1;
fd.ShowDialog();
Path= fd.FileName;
NotifyOfPropertyChange("Path");
}
public void Import()
{
if (Percorso != null)
{
IsBusy = true;
Text = "Generate..";
NotifyOfPropertyChange("IsBusy");
NotifyOfPropertyChange("Text");
Task.Factory.StartNew(() => GoNew());
}
else
{
MessageBox.Show("Select file!", "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
public void GoNew()
{
WindowManager.ShowWindow(new BViewModel(Path), null, null);
Execute.OnUIThread(() =>
{
IsBusy = false;
NotifyOfPropertyChange("IsBusy");
Text = "";
NotifyOfPropertyChange("Text");
});
}
}
我能做些什麼?
難道是用'WindowManager.ShowWindow'不是在UI線程上做什麼?看起來其他所有內容都被編組到UI線程 - 哪一行會引發錯誤? – Charleh
This line:WindowManager.ShowWindow(new BViewModel(Path),null,null); – puti26