-1

Description

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.

Update

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?

enter image description here

ShellViewModel.cs

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();
        //}
    }
}

UserControl Constructor

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;
        }

Usercontrol Method to change the view

public void ClickImport()
{
    shell.ChangeView<GcsImportProgressViewModel>();
}
Lukas Gund
  • 639
  • 1
  • 9
  • 27
  • Does `shell.DashboardView();` work? Is `ClickImport` invoked as expected? How do you instantiate `GcsImportViewModel`? – mm8 Jul 15 '21 at 18:28
  • shell.DashboardView(); does only work if it called in the shell xaml. ClickImport is just a button who should change the view and I see with a breakpoint that he jump to ChangeView method. But the view isn´t changing. – Lukas Gund Jul 15 '21 at 19:27
  • You didn't answer my other questions, particularly the one about how you instantiate the view models. – mm8 Jul 16 '21 at 08:06
  • I´ve a button with x:Name GcsImportView. There will be load the ActivateItemAsync(IoC.Get()); into the contentcontrol – Lukas Gund Jul 16 '21 at 08:09
  • So? It's still unclear how you create `GcsImportViewModel`? – mm8 Jul 16 '21 at 08:10
  • IoC.Get() create the object with dependency? – Lukas Gund Jul 16 '21 at 08:13
  • So how are you registering the `ShellViewModel`? Are you sure that you operate on the same instance? – mm8 Jul 16 '21 at 08:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234959/discussion-between-lukas-gund-and-mm8). – Lukas Gund Jul 16 '21 at 08:18

1 Answers1

1

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>();
mm8
  • 163,881
  • 10
  • 57
  • 88