[英]Caliburn.Micro Navigation from Usercontrol over ShellViewModel
我在版本 4 中使用 Caliburn.Micro 並嘗試從用戶控件導航到另一個頁面。 ShellView.xaml 有一個<ContentControl x:Name="ActiveItem" />
元素和所有導航方法,如DashboardView()
、 GcsImportView()
... 只要我在 ShellView.xaml 中就可以工作。 但是,如果我從用戶控件(在 ContentControl 內)調用,則什么也不會發生。 我什至沒有得到錯誤。 我可以多次按下按鈕而沒有任何反應。 我希望有人能在這里幫助我。
即使我嘗試這些站點的代碼,它也不起作用。 在調試時,ActiveItem 值將被更改。 這看起來像一個錯誤?
namespace GCS.ViewModels
{
public class ShellViewModel : Conductor<object>//, IHandle<GcsImportProgressViewModel>
{
private string _version = "v. " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string Version
{
get { return _version; }
}
public ShellViewModel(/*IEventAggregator eventAggregator*/)
{
DashboardView();
//eventAggregator.SubscribeOnUIThread(this);
}
public void DashboardView() => ActivateItemAsync(new DashboardViewModel());
public void GcsImportView() => ActivateItemAsync(IoC.Get<GcsImportViewModel>());
public void GcsExportView() => ActivateItemAsync(new GcsExportViewModel());
public void ChangeView<T>() => ActivateItemAsync(IoC.Get<T>());
//public Task HandleAsync(GcsImportProgressViewModel message, CancellationToken cancellationToken)
//{
// throw new NotImplementedException();
//}
}
}
public GcsImportViewModel(ShellViewModel shell, IGcsRepository gcsRepository/)
{
filePath = "Bitte GCS Excel Datei auswählen";
databases = new ObservableCollection<GcsTable>(gcsRepository.GetAllTables());
selectedDatabase = databases.FirstOrDefault();
this.gcsRepository = gcsRepository;
}
public void ClickImport()
{
shell.ChangeView<GcsImportProgressViewModel>();
}
您似乎是在ChangeView
的不同實例上調用ShellViewModel
。
您應該在引導程序中將視圖模型注冊為單例:
container.Singleton<ShellViewModel, ShellViewModel>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.