I use the Caliburn.Micro in version 4 and try to navigatie from a Usercontrol to another page. The ShellView.xaml has a <ContentControl x:Name="ActiveItem" />
element and all navigationmethods like DashboardView()
, GcsImportView()
... work aslong I am inside the ShellView.xaml. But if I call from a Usercontrol (inside the ContentControl) nothing happens. 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. 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
.
You should register the view model as a singleton in your bootstrapper:
container.Singleton<ShellViewModel, ShellViewModel>();