none
Replace treeview navigation in custom shell RRS feed

  • Question

  • I would like to iterate all the Navigation group items from my custom shell. However the following code is only showing that my app only has 1 group where in fact I have 3...

            foreach (var group in this.ServiceProxy.NavigationViewModel.NavigationItems)
       {
                       MessageBox.Show(group.DisplayName); 
       }

    Any ideas please? 

    Paul.



    Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com

    Friday, February 17, 2012 5:57 PM

Answers

  • Hi Hale,

    As you have mentioned that you have purchased the Washington's minimal.

    I suggest you to connect the Michael Washington for more help.



    • Marked as answer by Otomii Lu Monday, February 27, 2012 1:50 AM
    Wednesday, February 22, 2012 1:25 AM

All replies

  • Hi Paul

    I haven't got a link on hand, but I think this is something to do with the fact that the ViewModel hasn't been fully populated yet. In one example, I saw something like reading this.ServiceProxy.NavigationViewModel.NavigationItems.Count into a variable just to force it to get all the items.

    Hope this gives you a start.

    Regards

    Paul

    Friday, February 17, 2012 6:45 PM
  • Hi Hale

    I suggest you to refer the sample below:

    http://code.msdn.microsoft.com/silverlight/NavigationDemo-having-some-f2629c9c

    I think it will solve your problem.

    If you still have the question, please let me know

    Monday, February 20, 2012 2:34 AM
  • Thanks Paul,

    I have tried this but no luck. ExecuteAsync() always appears to be false. "It is not valid to call ExecuteAsync() because CanExecuteAsync is false"
    For example, if I try and run the following code on the Shell loaded event and try to open the default screen my app just hangs forever...

                // Open the Default Screen

                // The navigation view model will only return those links that can be executed.  In order

                // to do that, it will call the CanExecute() method on the links - which is an

                // asynchronous operation. 

                // "prime" the view model by asking for the links.  If we don't do this, the first

                // command entered in the shell will not work (all commands after that will work).

                int inttmp = this.ServiceProxy.NavigationViewModel.NavigationItems.Count();


                // Getthe Tasks group as a INavigationItem

                INavigationItem objINavigationItem =

                    (this.ServiceProxy.NavigationViewModel.DefaultItem as INavigationItem);

                // Cast the INavigationItem to a INavigationGroup

                INavigationGroup objINavigationGroup = (INavigationGroup)objINavigationItem;

                if (objINavigationGroup.DefaultChild is INavigationScreen)

                {

                    // Get the Default Screen

                    INavigationScreen objINavigationScreen = (INavigationScreen)objINavigationGroup.DefaultChild;

                    // Set DefaultScreenName

                    string DefaultScreenName = objINavigationScreen.DisplayName;

                    // The screen may not be ready yet

                    // Wait until the screen can be opened

                    while (!objINavigationScreen.ExecutableObject.CanExecuteAsync)

                    {

                        // Do nothing until the screen can be opened

                    }

                    // Open the Default Screen

                    objINavigationScreen.ExecutableObject.ExecuteAsync();



    Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com

    Monday, February 20, 2012 11:38 AM
  • Thanks for the link. However this doesnt really help as all I want to do is itterate through the groups and screen names defined in my LightSwitch app.

    I cant help but think if Microsoft released the deafult shell's code it would save a lot of people a lot of time.


    Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com

    Monday, February 20, 2012 11:41 AM
  • Hi Hale,

    Please refer to the link below:

    http://janvanderhaegen.wordpress.com/2011/09/07/extensions-made-easy-source-code-published/

    GO to download the code.

    ExtensionsMadeEasy.Client=>Navigation=>ScreenOpener.cs=>FindLink Method

    You can find the NavigationItem in the this.ServiceProxy.NavigationViewModel.NavigationItems have two type:

    NavigationItem is INavigationGroup or NavigationItem is INavigationScreen

    If NavigationItem is INavigationGroup, you should foreach in the INavigationGroup.Children to get the INavigationScreen

    If you have anything unsure, please let me know

    Tuesday, February 21, 2012 5:46 AM
  • Thanks for the link Otomii,

    Im a fan of Jan Van Der Haegen's blog but I am trying to do this without any 3rd party extensions. 

    I have since made progress - I purchased Michael Washington's minimal shell from here http://lightswitchhelpwebsite.com/Market/Shells/MinimalShell.aspx as I thought it would be worth 20 Bucks just to see where I am going wrong. When reviewing Michael's shell I found that the code he was using to open the default screen was almost identical to mine (published earlier in this thread) but gave exactly the same problem.

    I then created a new LS project and found that both the Minimal Shell and my own Shell worked as expected.

    Conclusion is there is something in my LS app that is causing the error I have been experincing. I will investigate when I can and post back here in case anyone else has similar probelms.

    Paul. 


    Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com

    Tuesday, February 21, 2012 9:27 AM
  • Hi Hale,

    As you have mentioned that you have purchased the Washington's minimal.

    I suggest you to connect the Michael Washington for more help.



    • Marked as answer by Otomii Lu Monday, February 27, 2012 1:50 AM
    Wednesday, February 22, 2012 1:25 AM