[英]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.