none
Collapsing/Hiding the Menu and RibbonBar on startup using code

    Question

  • I can get away with the default shell in my **web-based** application if I can find a way in code to a) hide the ribbon bar at the top and b) minimize the menu on the left on application start-up.

    Using Silverlight Spy I have found the following:

    RibbonBar at Top:
    Type: Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.RibbonCommandBar
    Name: HomeTabItem
    How to hide: set .Visiblity from Visible to Collapsed

    Menu on Left Side:
    Type: Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.ScreenNavigationTreeView
    Name of expanded menu: ExpandedTree
    Name of collapsed menu: CollapsedTree 
    How to collapse: set ExpandTree.Visiblity from Visible to Collapsed and set CollapsedTree.Visibility from Collapsed to Visible

    EDIT: As can bee seen from the marked answer post below, we actually need the NavigationView type control named "NavigationView" to manipulate the menu and not the ExpandedTree and CollapsedTree components as they are just child components of the actual menu.

    Now I need to find out how and where to put the code to do the above. I assume that the Application_Initialize() method would be a good place to start.

    Does anyone know how one would go about accessing those controls from the Application_Initialize() to set the appropriate properties. Even if I could just get access to the root-most control I would be able to find them.

    Thanks in advance


    Xander



    • Edited by novascape Wednesday, August 31, 2011 11:02 PM
    Wednesday, August 31, 2011 6:33 AM

Answers

  • I've solved this!! You can hide and/or collapse both the menu and the toolbar on start-up using code.

    I've provided a helper class with some static methods to hide or collapse the menu or toolbar that you can put in your Client/UserCode folder.

    I've tried various hooks during application start-up to call these from (e.g. Application_Initialized() and Application_LoggedIn() methods which work as long as you do not have to log in, as you would after deployment!) but in the end the one that works in all scenarios is the StartupScreen_Run() method in the Application class.

    ///////////////////////////////////////////////////////////////////////////////////////////////

    // Example usage:

    partial void MyStartupScreen_Run(ref bool handled)
    {
        //Helpers.HideMenu();
        //Helpers.HideRibbonBar();

        Helpers.CollapseMenu();          
        Helpers.CollapseRibbonBar();

        handled = false;
    }

    if you'd still like to have the toolbar hidden during deployment, but available and collapsed during debug mode (to allow runtime screen design) you can use the following directive:

    #if DEBUG
          Helpers.CollapseRibbonBar();
    #else
          Helpers.HideRibbonBar();
    #endif


    ///////////////////////////////////////////////////////////////////////////////////////////////

    Helper class - put in the Client/UserCode folder in the Client project:

    note: add a reference to the Microsoft.Lightswitch.Client.Internal assembly to your client project.

    using Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard;
    using System.Windows;
    using System.Windows.Media;

    namespace LightSwitchApplication.UserCode
    {
        public class Helpers
        {
            /// <summary>
            /// Hide the mnain menu altogether
            /// </summary>
            public static void HideMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.Visibility = Visibility.Collapsed;
                });
            }

            /// <summary>
            /// Collapse the main menu
            /// </summary>
            public static void CollapseMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.IsExpanded = false;
                });
            }

            /// <summary>
            /// Hide the RibbonBar altogether
            /// </summary>
            public static void HideRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.Visibility = Visibility.Collapsed;
                });
            }

            /// <summary>
            /// Collapse the toolbar altogether
            /// </summary>
            public static void CollapseRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.IsCompressed = true;
                });
            }

            /// <summary>
            /// Get the Main Menu Control
            /// </summary>
            private static NavigationView MainMenu
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (NavigationView)FindControlByName(root, "NavigationView");
                }
            }

            /// <summary>
            /// Get the Main RibbonBar Control
            /// </summary>
            private static RibbonCommandBar RibbonBar
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (RibbonCommandBar)FindControlByName(root, "HomeTabItem");
                }
            }

            /// <summary>
            /// Find a control with the specified Name (recursively) - returns null if not found.
            /// </summary>
            public static DependencyObject FindControlByName(DependencyObject control, string name)
            {
                if (control == null)
                    return null;

                if (control.GetValue(FrameworkElement.NameProperty) != null && control.GetValue(FrameworkElement.NameProperty).ToString() == name)
                {
                    return control;
                }

                // When it is a ScrollViewer we need to use the .Content property
                if (control.GetType().Equals(typeof(ScrollViewer)))
                    control = ((ScrollViewer)control).Content as FrameworkElement;

                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(control); i++)
                {
                    var child = FindControlByName(VisualTreeHelper.GetChild(control, i), name);
                    if (child != null)
                    {
                        return child;
                    }
                }
                return null;
            }


        }
    }

    Hope this helps someone (and marking my own post as the answer :)).


    Xander


    • Marked as answer by novascape Wednesday, August 31, 2011 10:20 AM
    • Unmarked as answer by novascape Wednesday, August 31, 2011 10:54 AM
    • Marked as answer by novascape Wednesday, August 31, 2011 8:59 PM
    • Edited by novascape Wednesday, August 31, 2011 9:12 PM formatting
    Wednesday, August 31, 2011 9:48 AM

All replies

  • Making progress here as I can get the root page like this:

            partial void Application_Initialize()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    if (root != null)
                    {
                        // ... locate the menu and ribbon and set properties...
                    }
                });
            }

     


    Xander
    • Proposed as answer by Jeeva Jose Friday, February 08, 2013 11:45 AM
    Wednesday, August 31, 2011 6:53 AM
  • I've solved this!! You can hide and/or collapse both the menu and the toolbar on start-up using code.

    I've provided a helper class with some static methods to hide or collapse the menu or toolbar that you can put in your Client/UserCode folder.

    I've tried various hooks during application start-up to call these from (e.g. Application_Initialized() and Application_LoggedIn() methods which work as long as you do not have to log in, as you would after deployment!) but in the end the one that works in all scenarios is the StartupScreen_Run() method in the Application class.

    ///////////////////////////////////////////////////////////////////////////////////////////////

    // Example usage:

    partial void MyStartupScreen_Run(ref bool handled)
    {
        //Helpers.HideMenu();
        //Helpers.HideRibbonBar();

        Helpers.CollapseMenu();          
        Helpers.CollapseRibbonBar();

        handled = false;
    }

    if you'd still like to have the toolbar hidden during deployment, but available and collapsed during debug mode (to allow runtime screen design) you can use the following directive:

    #if DEBUG
          Helpers.CollapseRibbonBar();
    #else
          Helpers.HideRibbonBar();
    #endif


    ///////////////////////////////////////////////////////////////////////////////////////////////

    Helper class - put in the Client/UserCode folder in the Client project:

    note: add a reference to the Microsoft.Lightswitch.Client.Internal assembly to your client project.

    using Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard;
    using System.Windows;
    using System.Windows.Media;

    namespace LightSwitchApplication.UserCode
    {
        public class Helpers
        {
            /// <summary>
            /// Hide the mnain menu altogether
            /// </summary>
            public static void HideMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.Visibility = Visibility.Collapsed;
                });
            }

            /// <summary>
            /// Collapse the main menu
            /// </summary>
            public static void CollapseMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.IsExpanded = false;
                });
            }

            /// <summary>
            /// Hide the RibbonBar altogether
            /// </summary>
            public static void HideRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.Visibility = Visibility.Collapsed;
                });
            }

            /// <summary>
            /// Collapse the toolbar altogether
            /// </summary>
            public static void CollapseRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.IsCompressed = true;
                });
            }

            /// <summary>
            /// Get the Main Menu Control
            /// </summary>
            private static NavigationView MainMenu
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (NavigationView)FindControlByName(root, "NavigationView");
                }
            }

            /// <summary>
            /// Get the Main RibbonBar Control
            /// </summary>
            private static RibbonCommandBar RibbonBar
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (RibbonCommandBar)FindControlByName(root, "HomeTabItem");
                }
            }

            /// <summary>
            /// Find a control with the specified Name (recursively) - returns null if not found.
            /// </summary>
            public static DependencyObject FindControlByName(DependencyObject control, string name)
            {
                if (control == null)
                    return null;

                if (control.GetValue(FrameworkElement.NameProperty) != null && control.GetValue(FrameworkElement.NameProperty).ToString() == name)
                {
                    return control;
                }

                // When it is a ScrollViewer we need to use the .Content property
                if (control.GetType().Equals(typeof(ScrollViewer)))
                    control = ((ScrollViewer)control).Content as FrameworkElement;

                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(control); i++)
                {
                    var child = FindControlByName(VisualTreeHelper.GetChild(control, i), name);
                    if (child != null)
                    {
                        return child;
                    }
                }
                return null;
            }


        }
    }

    Hope this helps someone (and marking my own post as the answer :)).


    Xander


    • Marked as answer by novascape Wednesday, August 31, 2011 10:20 AM
    • Unmarked as answer by novascape Wednesday, August 31, 2011 10:54 AM
    • Marked as answer by novascape Wednesday, August 31, 2011 8:59 PM
    • Edited by novascape Wednesday, August 31, 2011 9:12 PM formatting
    Wednesday, August 31, 2011 9:48 AM
  • Hmm, I commented earlier, but my post seems to have disappeared.

    So I'll congratulate you again here. Cool stuff!

    You provided the answer, why shouldn't you mark it as such.


    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, August 31, 2011 10:41 AM
  • Thanks Yann :)

    Actually there appears to be an object reference not set problem with the CollapseMenu() method when running as a deployed app when it prompts you to log in. I will investigate it and post a fix if possible. Works fine in debug mode without the login screen. Might have to look for another event...

    Will add a comment about this in the post above as well... unmarking as answer until I find a fix.

     


    Xander
    Wednesday, August 31, 2011 10:53 AM
  • So, as I've now discovered, you cannot call those helper methods in the Application_LoggedIn() method if you actually have to log in as the controls do not appear to be available at that point yet. Runing from within VS.NET where you don't log in works just fine.

    As a work around, you can call these helper methods in the Xxx_InitializeDataWorkspace() or Xxx_Activated() methods of your start-up screen and then it works correctly without error, but it is not ideal as you will momentarily see see the menu and ribbon bar before they are collapsed/hidden.

    We need to find the correct event/method to call these from... anyone have any ideas? We're almost there...

    Thanks


    Xander


    Wednesday, August 31, 2011 11:26 AM
  • Xander, I haven't been able to test anything yet. What assembly gives you the namespace:

    Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard?


    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, August 31, 2011 11:41 AM
  • It's OK, I found it: Microsoft.LightSwitch.Client.Internal

    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, August 31, 2011 12:07 PM
  • +1 for me, too.   This is huge.  Thanks, Xander.

    Wednesday, August 31, 2011 7:17 PM
  • Solved the start-up hook that you need to call it from. Basically needs to be called in the MyStartupScreen_Run(ref bool handled) method (that is implementing a Xxx_Run() method for your start-up screen). That works in all scenarios and does not cause the menu and toolbar to be shown momentarily.

    Yann, only saw your question this morning, but have made mention of that assembly that should be referenced in the answer post above. Garth, glad to have helped.

    I have updated the answer post above and fixed it with the correct calling code and also added a comment about using the DEBUG directive to still show the toolbar during debug to allow run-time screen design. Also remarked it as the answer.

    Now that we have this working - and it will allow me to use the default shell now - I don't think it will be a huge leap to now hook into that menu and toolbar to manipulate it even more at run-time. Say adding another control like a drop down onto the toolbar...

    Regards


    Xander




    Wednesday, August 31, 2011 9:04 PM
  • Great work Xander! And thanks for sharing it with everyone..

    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, August 31, 2011 11:05 PM
  • To all

    Would it be possible to list the vb.net version of the code since i listed the orginal request and was told to generate a new shell. Sorry iam a beginner with vb.net i come from the foxpro world.

     

    thanks

    leonard

    Thursday, September 01, 2011 3:40 PM
  • Hi Leonard,

    You may want to bookmark this link http://www.developerfusion.com/tools/convert/csharp-to-vb/

    and convert it yourself.

     

    Dave

    Thursday, September 01, 2011 3:49 PM
  • To all

    Would it be possible to list the vb.net version of the code since i listed the orginal request and was told to generate a new shell. Sorry iam a beginner with vb.net i come from the foxpro world.

     

    thanks

    leonard


    This is a free site to convert code between C# and VB (and vice versa).   Please bookmark this for future reference.
    Thursday, September 01, 2011 5:11 PM
  • hi xander,

    tks for amazing code, i cell these in event/method in


            Private Sub homescreen_CanRun(ByRef result As Boolean)


                Application.Helpers.HideRibbonBar()

                result = True '  Application.Current.User.HasPermission(canhomescreen)


            End Sub

     

    and work

     

     

    tks

    Rodrigo

    Thursday, September 08, 2011 4:00 AM
  • You are welcome Rodrigo. Since you seem to have the VB version compiling and running, do you mind posting the VB code equivalent here for the VB users?

    Thanks


    Xander
    Thursday, September 08, 2011 4:23 AM
  • hi! this translated vb version works for me, feel free to make corrections where is needed.. :)

     

    Imports Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard
    Imports System.Windows
    Imports System.Windows.Media
    Imports Microsoft.LightSwitch.Threading
    Imports System.Windows.Controls
    
    
    'if you'd still like to have the toolbar hidden during deployment, but available and 
    'collapsed during debug mode (to allow runtime screen design) you can use the following
    ' directive:
    
    '#If DEBUG Then
    '      Helpers.CollapseRibbonBar();
    '#Else
    '      Helpers.HideRibbonBar();
    '#End If
    
    Namespace LightSwitchApplication
        Public Class MenuRibbonHelper
            ''' <summary>
            ''' Hide the mnain menu altogether
            ''' </summary>
            Public Shared Sub HideMenu()
                Dispatchers.Main.Invoke(Sub()
                                            MainMenu.Visibility = Visibility.Collapsed
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Collapse the main menu
            ''' </summary>
            Public Shared Sub CollapseMenu()
                Dispatchers.Main.Invoke(Sub()
                                            MainMenu.IsExpanded = False
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Hide the RibbonBar altogether
            ''' </summary>
            Public Shared Sub HideRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            RibbonBar.Visibility = Visibility.Collapsed
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Collapse the toolbar altogether
            ''' </summary>
            Public Shared Sub CollapseRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            RibbonBar.IsCompressed = True
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Get the Main Menu Control
            ''' </summary>
            Private Shared ReadOnly Property MainMenu() As NavigationView
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Return DirectCast(FindControlByName(root, "NavigationView"), NavigationView)
                End Get
            End Property
    
            ''' <summary>
            ''' Get the Main RibbonBar Control
            ''' </summary>
            Private Shared ReadOnly Property RibbonBar() As RibbonCommandBar
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Return DirectCast(FindControlByName(root, "HomeTabItem"), RibbonCommandBar)
                End Get
            End Property
    
            ''' <summary>
            ''' Find a control with the specified Name (recursively) - returns null if not found.
            ''' </summary>
            Public Shared Function FindControlByName(control As DependencyObject, name As String) As DependencyObject
                If control Is Nothing Then
                    Return Nothing
                End If
    
                If control.GetValue(FrameworkElement.NameProperty) IsNot Nothing AndAlso control.GetValue(FrameworkElement.NameProperty).ToString() = name Then
                    Return control
                End If
    
                ' When it is a ScrollViewer we need to use the .Content property
                If control.[GetType]().Equals(GetType(ScrollViewer)) Then
                    control = TryCast(DirectCast(control, ScrollViewer).Content, FrameworkElement)
                End If
    
                For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(control) - 1
                    Dim child = FindControlByName(VisualTreeHelper.GetChild(control, i), name)
                    If child IsNot Nothing Then
                        Return child
                    End If
                Next
                Return Nothing
            End Function
    
        End Class
    End Namespace
    

     

    hope it helps!

    Kivito


    • Edited by Kivito Thursday, September 08, 2011 8:51 AM
    • Proposed as answer by c4ctopus Friday, August 03, 2012 4:59 PM
    Thursday, September 08, 2011 7:45 AM
  • Someone asked a question in the last day on this thread about how to hide a menu group. The post must have been deleted again as I cannot find it.

    Anyway, the answer is that if you ensure that *all* the menu items within a menu group cannot be run, then the menu group will not be displayed either.

    You can hide or show menus for users in different roles by editing the <Screen>_CanRun method in the application code, accessible when right licking on the [Screens] node in the project and selecting "Edit Screen Navigation" from the popup menu.

    I also had a quick look at the underlying XAML model to see whether we could add a helper method to show or hide an entire menu group, but I was not able to find a solution in a short space of time.

    Regards


    Xander
    Friday, September 23, 2011 11:35 PM
  • Awesome!

    Thanks

    Tuesday, September 27, 2011 7:42 PM
  • Can someone please help a newbie out, I've looked everywhere for that Microsoft.Lightswitch.Client.Internal assembly but i cannot seem to figure out what you are talking about. I right click references in the client portion of my app and choose add reference but then it is not listed under .NET - in fact there is not a single one that says anything about lightswitch. I am using visual studio 2010 ultimate with lightswitch released version.
    Friday, September 30, 2011 7:14 PM
  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\LightSwitch\1.0\Client
    Friday, September 30, 2011 7:29 PM
  • Hi, great work here - it gave me the clues I needed to figure out my own requirement!

     

    In my admin application, I have a custom Logon screen that handles authentication directly to the database via a WCF RIA Service (My main app uses a custom .net memberprovider which I couldn't implement in LS). Anyway, I need to close the Logon screen and remove it from the Task menu once the user is authenticated.

    I know people have asked about hiding menu groups directly and my approach to hiding the Logon menu item also works with menu groups!! (the Screen_CanRun method only seems to work one time, when the app is loaded - I needed to hide items after the app is running).

    I created my own little helper class that is based on Colin Eberhardt's excellent Linq to VisualTree class. You can learn about his class here: http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree

     

    Then my helper class is here:

     

    Imports System.Windows
    Imports System.Windows.Controls
    
    Imports LinqToVisualTree
    Imports Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard
    Imports Microsoft.LightSwitch.SilverlightUtilities.Controls.Internal
    
    
    
    ''' <summary>
    ''' A collection of functions exposing controls on a lightswitch screen
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Screen
    
        Public Shared Function MainMenu() As NavigationView
    
            MainMenu = (From d In Application.Current.RootVisual.Descendants
                       Where DirectCast(d, FrameworkElement).Name = "NavigationView").FirstOrDefault
    
        End Function
    
        Public Shared Function RibbonBar() As RibbonCommandBar
    
            RibbonBar = (From d In Application.Current.RootVisual.Descendants
                        Where DirectCast(d, FrameworkElement).Name = "HomeTabItem").FirstOrDefault
    
        End Function
    
    
        Public Shared Function MenuItem_Find(ByVal controlName As String) As FrameworkElement
    
            Dim menuItemTextBlock = (From d In MainMenu.Descendants
                                    Where TypeOf d Is TextBlock AndAlso
                                            DirectCast(d, TextBlock).Text = controlName).FirstOrDefault
    
            If menuItemTextBlock IsNot Nothing Then
    
                MenuItem_Find = (From a In menuItemTextBlock.Ancestors
                                Where TypeOf a Is ScreenNavigationTreeViewItem).FirstOrDefault
    
            Else
                MenuItem_Find = Nothing
    
            End If
    
        End Function
    
    
        Public Shared Sub MenuItem_SetVisibility(ByVal controlName As String, state As Visibility)
    
            Dim menuItem = MenuItem_Find(controlName)
    
            If menuItem IsNot Nothing Then menuItem.Visibility = state
    
        End Sub
    
    
        Public Shared Function RibbonBarItem_Find(ByVal controlName As String) As FrameworkElement
    
            Dim ribbonBarItemTextControl = (From d In RibbonBar.Descendants
                                            Where TypeOf d Is TwoLineTrimmableTextBlock AndAlso
                                                    DirectCast(d, TwoLineTrimmableTextBlock).Text = controlName).FirstOrDefault
    
            If ribbonBarItemTextControl IsNot Nothing Then
    
                RibbonBarItem_Find = (From a In ribbonBarItemTextControl.Ancestors
                                        Where TypeOf a Is RibbonButton).FirstOrDefault
            Else
                RibbonBarItem_Find = Nothing
    
            End If
    
        End Function
    
    
        Public Shared Sub RibbonBarItem_SetVisibility(ByVal controlName As String, state As Visibility)
    
            Dim ribbonBarItem = RibbonBarItem_Find(controlName)
    
            If ribbonBarItem IsNot Nothing Then ribbonBarItem.Visibility = state
    
        End Sub
    
    
    End Class
    
    
    
    
    

     

     

     

    An example usage is here (At app startup):

     

    ' Hide Menu/RibbonBar via UI thread
    Dispatchers.Main.Invoke(Sub() Screen.MainMenu.Visibility = Visibility.Collapsed)
    Dispatchers.Main.Invoke(Sub() Screen.RibbonBar.Visibility = Visibility.Collapsed)
    


    And after logon:

     

     

    ' Show Menu/RibbonBar via UI thread
    Dispatchers.Main.Invoke(Sub() Screen.MainMenu.Visibility = Visibility.Visible)
    Dispatchers.Main.Invoke(Sub() Screen.RibbonBar.Visibility = Visibility.Visible)
    
    ' Hide logon button via UI thread
    Dispatchers.Main.Invoke(Sub() Screen.MenuItem_SetVisibility("Logon", Visibility.Collapsed))
    


    I know its in VB but I hope it helps someone with similar requirements as myself :)

     

    Steve

     


    • Edited by samneric1 Tuesday, October 18, 2011 3:40 PM
    Tuesday, October 18, 2011 3:28 PM
  • Your link http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/

    has an extra word at the end and so it doesn't work.

    Tuesday, October 18, 2011 3:38 PM
  • Fixed, thanks!
    Tuesday, October 18, 2011 3:41 PM
  • Any time (well, almost every time time) that you need to manually add a reference to any of the LightSwitch assemblies, this is where you'll find them.

    You need to select "browse" & navigate to this folder, then select the assembly, & click "Add". They won't appear in the .NET section, becuase they're not in the GAC (Global Assembly Cache).


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    Tuesday, October 18, 2011 10:30 PM
  • I am not getting  Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard namespace please help.

    it shows Microsoft.LightSwitch.Runtime.Shell; but Implementation is not there please tell me which reference should I use?


    Neelesh
    Friday, February 03, 2012 9:11 AM
  • I had to add

    using Microsoft.LightSwitch.Threading;

    using Windows.System.Controls;

    before "Dispatchers" and "ScrollViewer" were recognised in novascape's code with VS LS 2012 RC.

    Thanks for posting this though, great help!

    Gus


    • Edited by GusBeare Monday, July 23, 2012 2:59 PM update
    Monday, July 23, 2012 2:50 PM
  • I also had to use the full path to the class to make it work, like this:

    LightSwitchApplication.UserCode.MenuHelpers.HideRibbonBar();

    I'm not much of a coder so I don't really understand why..

    Anyway, I was wondering if anyone had worked out how to hide the change password control at the bottom of the page?

    I am running my apps inside dotnetnuke web sites using the dotnetnuke credentials. But I don't want the user to see that change pwd control

    since they already have the dnn one.

    Any ideas?

    gus

    Monday, July 23, 2012 3:30 PM
  • You could also have added another "using" statement:

    using LightSwitchApplication.UserCode.MenuHelpers;

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Wednesday, July 25, 2012 4:16 AM
  • hi! this translated vb version works for me, feel free to make corrections where is needed.. :)

     

    Imports Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard
    Imports System.Windows
    Imports System.Windows.Media
    Imports Microsoft.LightSwitch.Threading
    Imports System.Windows.Controls
    
    
    'if you'd still like to have the toolbar hidden during deployment, but available and 
    'collapsed during debug mode (to allow runtime screen design) you can use the following
    ' directive:
    
    '#If DEBUG Then
    '      Helpers.CollapseRibbonBar();
    '#Else
    '      Helpers.HideRibbonBar();
    '#End If
    
    Namespace LightSwitchApplication
        Public Class MenuRibbonHelper
            ''' <summary>
            ''' Hide the mnain menu altogether
            ''' </summary>
            Public Shared Sub HideMenu()
                Dispatchers.Main.Invoke(Sub()
                                            MainMenu.Visibility = Visibility.Collapsed
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Collapse the main menu
            ''' </summary>
            Public Shared Sub CollapseMenu()
                Dispatchers.Main.Invoke(Sub()
                                            MainMenu.IsExpanded = False
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Hide the RibbonBar altogether
            ''' </summary>
            Public Shared Sub HideRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            RibbonBar.Visibility = Visibility.Collapsed
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Collapse the toolbar altogether
            ''' </summary>
            Public Shared Sub CollapseRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            RibbonBar.IsCompressed = True
                                        End Sub)
            End Sub
    
            ''' <summary>
            ''' Get the Main Menu Control
            ''' </summary>
            Private Shared ReadOnly Property MainMenu() As NavigationView
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Return DirectCast(FindControlByName(root, "NavigationView"), NavigationView)
                End Get
            End Property
    
            ''' <summary>
            ''' Get the Main RibbonBar Control
            ''' </summary>
            Private Shared ReadOnly Property RibbonBar() As RibbonCommandBar
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Return DirectCast(FindControlByName(root, "HomeTabItem"), RibbonCommandBar)
                End Get
            End Property
    
            ''' <summary>
            ''' Find a control with the specified Name (recursively) - returns null if not found.
            ''' </summary>
            Public Shared Function FindControlByName(control As DependencyObject, name As String) As DependencyObject
                If control Is Nothing Then
                    Return Nothing
                End If
    
                If control.GetValue(FrameworkElement.NameProperty) IsNot Nothing AndAlso control.GetValue(FrameworkElement.NameProperty).ToString() = name Then
                    Return control
                End If
    
                ' When it is a ScrollViewer we need to use the .Content property
                If control.[GetType]().Equals(GetType(ScrollViewer)) Then
                    control = TryCast(DirectCast(control, ScrollViewer).Content, FrameworkElement)
                End If
    
                For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(control) - 1
                    Dim child = FindControlByName(VisualTreeHelper.GetChild(control, i), name)
                    If child IsNot Nothing Then
                        Return child
                    End If
                Next
                Return Nothing
            End Function
    
        End Class
    End Namespace
    

     

    hope it helps!

    Kivito


    Thanks for converting this very cool post to VB.

    "HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD"

    HAROLD GLENN MINERVA
    http://hgminerva.wordpress.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. This will help other users to find their answer quickly.

    Wednesday, July 25, 2012 7:50 AM
  • that's the one, yes, thankfully I got there before you posted this one.

    I'm learning.. but it's a slow process..

    Thursday, July 26, 2012 7:39 AM
  • Hi,

    Thanks for this it works well for default Shell\theme, but broke in VS2012RC when I changed to cosmo shell\theme.  NullReferenceError on RibbonBar property.  Has anyone got this to work?  I'm guessing the new shell doen't have control named "HomeTabItem"(?)

    TIA,

    Josh

    • Edited by joshbooker Thursday, July 26, 2012 7:07 PM
    Thursday, July 26, 2012 7:05 PM
  • In Microsoft's attempt to "metro-fy" everything under the sun, it looks like the team was forced to create a default shell for LS that conforms to these new "metro standards".

    Even though not long ago MS was trying to convince everyone that the "Ribbon" was the next best thing to sliced bread (backed up by multiple usability studies of course), now everything has to work on a tablet or on a mobile phone (whether you're using a desktop PC or not). Such a paradigm doesn't use a ribbon any more (even though LS never used an "actual" ribbon, it was a "ribbon-like" control), therefore no "tabs" either.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Friday, July 27, 2012 5:07 AM
  • Thanks Yann.  Ribbon or no ribbon--Tabs or no tabs, the shell still has screen controls and nav controls.  I am still interested to know how to hide the Screen controls (Save, Refresh) and the Nav controls.  Can anyone help?
    • Edited by joshbooker Friday, July 27, 2012 10:15 AM
    Friday, July 27, 2012 10:14 AM
  • I haven't had the chance to look into it yet. I know that my Luminous Commands extension had weird results with the Cosmopolitan shell. My commands still appeared up under the menu (but over on the right-hand side), but Save, Refresh etc were down the bottom.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Friday, July 27, 2012 11:40 AM
  • Thanks Yann.  While in debug, I can see the cosmo shell appears wayyyyyy down the tree, but don't know how to read it well enough to determine the proper change to find the controls.  I know I need to change the FindControlControlByName to handle the new shell, but not sure how to start.   Any pointers?  Going back to old shell for now.

    TIA,

    Josh

    Thursday, August 02, 2012 3:24 PM
  • I haven't had the chance to play with the Cosmopolitan shell, or even LS V2 for that matter, so I'm not able to help you at the moment, sorry. As I said though, it did do something weird with the buttons of my Luminous Commands control (it put them in a different place to the Save/Refresh buttons).

    I remember thinking at the time I saw it, that it was an odd thing to do, moving the ribbon buttons down to the bottom of the screen, but now that I've seen the Windows 8 "App Bar" I can see why. I don't like it, but I can see why.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Friday, August 03, 2012 2:19 AM
  • Hi All,

    I have used above code to hide menu and it is working fine with LS2011. but It throwing error with LS2012 in below block of code.

    It is giving "Object reference error". It seems "NavigationView" name has been changed.

    return (NavigationView)FindControlByName(root, "NavigationView");


     Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.Visibility = Visibility.Collapsed;
                });
    Wednesday, December 05, 2012 6:36 AM
  • Hi, unfortunately I do not have time right now to look into it, but you'd want to use the free edition of Silverlight Spy to spy into the XAML controls of the running LS2 app to find the new name of appropriate control.

    If you can't find it I will try and look into it over the Xmas period - once I get this project delivery out of the way :D

    Regards


    Xander

    Wednesday, December 05, 2012 7:12 AM
  • Hi,

    Unfortunately, i could not be able to find name of menu. Please provide your support to find out the name.

    Regards,

    Shaikh

    Friday, December 07, 2012 9:35 AM
  • Hi
    I have managed to hide the top bar that showing the user name and loggo. In Cosmopolitan LS 2012.

    so you can try to change the code to hide other things :) place it in Application partial void MyStartupScreen_Run(ref bool handled)

    try
                {
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        var c = System.Windows.Application.Current;
                        (VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(c.RootVisual, 0), 0), 0), 0), 0), 0), 0) as Grid).Visibility = Visibility.Collapsed;
                    });
                }
                catch (Exception)
                {
                }

    /Daniel

    Thursday, November 14, 2013 1:32 PM