Luiscencio
Luiscencio

Reputation: 3965

How to Navigate to a user control on load?

I want to choose which user control to load but my MainWindowView is not even loaded yet so the region manager does not know any regions, How can I achieve this?

my bootstrapper looks like this:

    protected override DependencyObject CreateShell()
    {
        return this.Container.Resolve<MainWindowView>();
    }

    protected override void InitializeShell()
    {
        Application.Current.MainWindow.Show();
    }

    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();

        this.Container.RegisterTypeForNavigation<WorkTypeSelectionView>();
    }

and my viewmodel:

    public MainWindowViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
    {

        this.eventAggregator = eventAggregator;
        this.regionManager = regionManager;
        this.AuthenticateUser();

        if (this.LoggedUser.AvailableWorkTypes.Count > 1)
        {
            this.Navigate(nameof(WorkTypeSelectionView));
        }
    }

    private void Navigate(string obj)
    {
        this.regionManager.RequestNavigate(DefaultContentRegion, obj);
    }

thanks in advance!

EDIT:

Guess i was asking the wrong question, found this https://stackoverflow.com/a/7887936/171136 still want to explore other options. Thanks!

Upvotes: 0

Views: 99

Answers (1)

user5420778
user5420778

Reputation:

You can use View Discovery with regionManager.RegisterViewWithRegion("RegionName", typeof(View));. When the region is created, it will automatically inject the view.

Upvotes: 1

Related Questions