0

I am using Cimbalino navigation but the query param never gets set for me.

Main View Model

   private readonly INavigationService navigationService = null;
    public MainViewModel(INavigationService navigationService)
    {
        this.navigationService = navigationService;
        NavigateToPg2Cmd = new RelayCommand(() => NaviagateToPg2());
        NavigateToPg2WithParmsCmd = new RelayCommand(() => NaviagateToPg2WithParms()); 
    }

    private void NaviagateToPg2WithParms()
    {

        navigationService.NavigateTo(new Uri("/Views/SecondPg.xaml?parameter=1&parm2=2", UriKind.Relative));
    }

When I look into NavigationService the Query Param dictionary is always 0.

 static ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        if (ViewModelBase.IsInDesignModeStatic)
        {
        }
        else
        {

        }

        SimpleIoc.Default.Register<INavigationService, NavigationService>();

        SimpleIoc.Default.Register<MainViewModel>();
        SimpleIoc.Default.Register<SecondVM>();
    }

Edit Ok, I figured it out. When NavigateTo runs it still has not split the query string out yet so that's why it is zero.

I was also trying to do

   private readonly INavigationService navigationService = null;
        public SecondVM(INavigationService navigationService)
        {
            this.navigationService = navigationService;


            if (IsInDesignMode)
            {
                Message = "Design Mode";
            }
            else
            {
                if (navigationService.QueryString.ContainsKey("paramter"))
                {
                     Message = navigationService.QueryString["parameter"];
                }

            }



        }

what did not work either as I guess it was too early as well. I really would like to pull it out at constructor time though, is there a way to do this?

chobo2
  • 83,322
  • 195
  • 530
  • 832
  • Not sure what the problem could be just looking at this code... maybe try a working demo first and see if you can fit it for your app? Here is a complete example: http://developer.nokia.com/community/wiki/How_to_use_Cimbalino_Windows_Phone_Toolkit_-_NavigationService – Depechie Feb 14 '14 at 09:41
  • Thanks, that helped me figure out the problem but not sure what the soultion would be. The problem is that I guess the query string does not get split apart right away after the NavigateTo is triggered hence why I saw always zero. The other problem is that I tried to access the query string in the 2nd page constructor that seems to early as well to get it. – chobo2 Feb 14 '14 at 17:46

1 Answers1

1

I know it's not 100% the solution you are looking for, but you are true... You'll need to wait until the view is loaded before accessing the QueryString params in the ViewModel!

To do this, hook into the Loaded event of the view and pass it to a Command on the viewmodel!

If created a demo of this on my github to get you started: https://github.com/Depechie/NavigationParams

Depechie
  • 6,102
  • 24
  • 46
  • Cool, This might be the way I have to go. I guess then I could set a private property then use that property in the next line of the constructor(or do everything in ViewLoaded). – chobo2 Feb 17 '14 at 06:44
  • Well I tend to fire up other methods in the ViewLoaded :) – Depechie Feb 17 '14 at 08:31