[英]Caliburn.Micro Navigation from Usercontrol over ShellViewModel
I use the Caliburn.Micro in version 4 and try to navigatie from a Usercontrol to another page.我在版本 4 中使用 Caliburn.Micro 并尝试从用户控件导航到另一个页面。 The ShellView.xaml has a
<ContentControl x:Name="ActiveItem" />
element and all navigationmethods like DashboardView()
, GcsImportView()
... work aslong I am inside the ShellView.xaml. ShellView.xaml 有一个
<ContentControl x:Name="ActiveItem" />
元素和所有导航方法,如DashboardView()
、 GcsImportView()
... 只要我在 ShellView.xaml 中就可以工作。 But if I call from a Usercontrol (inside the ContentControl) nothing happens.但是,如果我从用户控件(在 ContentControl 内)调用,则什么也不会发生。 I don´t even get a error.
我什至没有得到错误。 I can push the Button thousend times without any respond.
我可以多次按下按钮而没有任何反应。 I hope somebody can help me here.
我希望有人能在这里帮助我。
Even if I try the code from these site it doesn´t work.即使我尝试这些站点的代码,它也不起作用。 On debugging the ActiveItem value will be changed.
在调试时,ActiveItem 值将被更改。 That looks like a bug?
这看起来像一个错误?
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>();
}
It seems like you are calling ChangeView
on a different instance of the ShellViewModel
.您似乎是在
ChangeView
的不同实例上调用ShellViewModel
。
You should register the view model as a singleton in your bootstrapper:您应该在引导程序中将视图模型注册为单例:
container.Singleton<ShellViewModel, ShellViewModel>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.