locked
Urgent: Collapsing/Hiding Menu Item and Ribbon Item... RRS feed

  • Question

  • Please Help...

    I am using VB.Net LightSwitch code below to "Collapse/Hide" the Screen Navigation Shell (to hide the "menu Items" and Ribbon Bar").  Took the code from a nice article in the Forum here.  It works perfect for the "Standard Shell" but not for the "Cosmopolitan Shell".  I use 2 root names ""NavigationView" and "HomeTabItem".  As the "Standard Shell" works, I was wondering if the "Cosmopolitan Shell" names have changed.  Code below doesn't seem to see the "Cosmopolitan Shell".  Can someone please help as there is little information on this subject.  Thank you.

    Ed 

    Imports Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard
    Imports System.Windows
    Imports System.Windows.Media
    Imports Microsoft.LightSwitch.Threading
    Imports System.Windows.Controls
    Imports Microsoft.LightSwitch.SilverlightUtilities.Controls.Internal
    'Imports LightSwitchApplication.UserCode.MenuHelpers
    
    Namespace LightSwitchApplication
    
        Public Class SignIn
    
            Private Sub Hide_Execute()
                ' Set result to the desired field value
                HideMenu()
                CollapseRibbonBar()
                HideRibbonBar()
            End Sub
    
            ' Hide the mnain menu altogether
            Public Shared Sub HideMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
    
            ' Collapse the main menu
            Public Shared Sub CollapseMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.IsExpanded = False
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
    
            ' Hide the RibbonBar altogether
            Public Shared Sub HideRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
    
            ' Collapse the toolbar altogether
            Public Shared Sub CollapseRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.IsCompressed = True
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
    
            ' Get the Main Menu Control
            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
    
            ' Get the Main RibbonBar Control
            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
    
    
            ' Find a control with the specified Name (recursively) - returns null if not found.
            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

        



    Edward Piccoli

    Thursday, April 3, 2014 3:54 PM

Answers

  • Hi Edward,

    I thought that you would work it out from my listings and directions. Here is some code that works but needs cleaning-up a bit:

            Private Sub Hide_Execute()
                ' Set result to the desired field value
                HideMenu()
                CollapseRibbonBar()
                HideRibbonBar()
            End Sub
    
            ' Hide the mnain menu altogether
            Public Shared Sub HideMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                            Try
                                                MainMenuCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Collapse the main menu
            Public Shared Sub CollapseMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.IsExpanded = False
                                            Catch
                                            End Try
                                            Try
                                                MainMenuCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Hide the RibbonBar altogether
            Public Shared Sub HideRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                            Try
                                                RibbonBarCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Collapse the toolbar altogether
            Public Shared Sub CollapseRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.IsCompressed = True
                                            Catch
                                            End Try
                                            Try
                                                RibbonBarCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Get the Main Menu Control
            Private Shared ReadOnly Property MainMenu() As NavigationView
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim navView = FindControlByName(root, "NavigationView")
                    Return DirectCast(navView, NavigationView)
                End Get
            End Property
    
            ' Get the Main Menu Control
            Private Shared ReadOnly Property MainMenuCosmo() As Cosmopolitan.Presentation.Controls.OverflowControl
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim navViewCosmo = FindControlByName(root, "NavigationItems")
                    Return DirectCast(navViewCosmo, Cosmopolitan.Presentation.Controls.OverflowControl)
                End Get
            End Property
    
            ' Get the Main RibbonBar Control
            Private Shared ReadOnly Property RibbonBar() As RibbonCommandBar
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim ribbon = FindControlByName(root, "HomeTabItem")
                    Return DirectCast(ribbon, RibbonCommandBar)
                End Get
            End Property
    
            ' Get the Main RibbonBar Control
            Private Shared ReadOnly Property RibbonBarCosmo() As Cosmopolitan.Presentation.Controls.OverflowControl
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim ribbonCosmo = FindControlByName(root, "CommandItems")
                    Return DirectCast(ribbonCosmo, Cosmopolitan.Presentation.Controls.OverflowControl)
                End Get
            End Property
    

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Monday, April 7, 2014 7:39 PM

All replies

  • Here is the first:

            <ctls:OverflowControl x:Name="NavigationItems"
                Grid.Row="1"
                shel:ComponentViewModelService.ViewModelName="Default.NavigationViewModel"
                Style="{StaticResource NavigationStyle}"
                ItemsSource="{Binding NavigationItems}"
                ItemTemplate="{StaticResource NavigationGroupTemplate}"
                OverflowTemplate="{StaticResource NavigationOverflowTemplate}"
                Visibility="{Binding NavigationItems, Converter={StaticResource EnumerableToVisibilityConverter}}">

    Not sure if the ribbon is named.

    The source code is here Cosmopolitan

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Thursday, April 3, 2014 7:07 PM
  • Thank you Dave for information.  I have looked at the Cosmopolitan code you mentioned but so far have not been able to come up with a solution for what might be the problem hiding Menu Item and Navigation Group (Ribbon) using the Cosmopolitan Shell.  Will keep looking at this and somewhere their must be a clue...  Thanks again

    Ed

     

    Edward Piccoli

    Friday, April 4, 2014 8:36 AM
  • Hi Ed,

    The 'DirectCast' will likely not work as NavigationView is the wrong type. It is possible to walk around the visual tree without names which may be the case here.

    The second is here I think:

                        <ctls:OverflowControl x:Name="CommandItems"
                            ItemsSource="{Binding ActiveScreens.Commands}"
                            ItemTemplate="{StaticResource ScreenCommandTemplate}"
                            OverflowTemplate="{StaticResource ScreenCommandsOverflowTemplate}"
                            IsEnabled="{Binding ActiveScreens.AreCommandsEnabled}"
                            HorizontalAlignment="Center"
                            Margin="0" Grid.ColumnSpan="2">
    

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Friday, April 4, 2014 8:45 AM
  • Hi Edward,

    I thought that you would work it out from my listings and directions. Here is some code that works but needs cleaning-up a bit:

            Private Sub Hide_Execute()
                ' Set result to the desired field value
                HideMenu()
                CollapseRibbonBar()
                HideRibbonBar()
            End Sub
    
            ' Hide the mnain menu altogether
            Public Shared Sub HideMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                            Try
                                                MainMenuCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Collapse the main menu
            Public Shared Sub CollapseMenu()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                MainMenu.IsExpanded = False
                                            Catch
                                            End Try
                                            Try
                                                MainMenuCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Hide the RibbonBar altogether
            Public Shared Sub HideRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                            Try
                                                RibbonBarCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Collapse the toolbar altogether
            Public Shared Sub CollapseRibbonBar()
                Dispatchers.Main.Invoke(Sub()
                                            Try
                                                RibbonBar.IsCompressed = True
                                            Catch
                                            End Try
                                            Try
                                                RibbonBarCosmo.Visibility = Visibility.Collapsed
                                            Catch
                                            End Try
                                        End Sub)
            End Sub
    
            ' Get the Main Menu Control
            Private Shared ReadOnly Property MainMenu() As NavigationView
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim navView = FindControlByName(root, "NavigationView")
                    Return DirectCast(navView, NavigationView)
                End Get
            End Property
    
            ' Get the Main Menu Control
            Private Shared ReadOnly Property MainMenuCosmo() As Cosmopolitan.Presentation.Controls.OverflowControl
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim navViewCosmo = FindControlByName(root, "NavigationItems")
                    Return DirectCast(navViewCosmo, Cosmopolitan.Presentation.Controls.OverflowControl)
                End Get
            End Property
    
            ' Get the Main RibbonBar Control
            Private Shared ReadOnly Property RibbonBar() As RibbonCommandBar
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim ribbon = FindControlByName(root, "HomeTabItem")
                    Return DirectCast(ribbon, RibbonCommandBar)
                End Get
            End Property
    
            ' Get the Main RibbonBar Control
            Private Shared ReadOnly Property RibbonBarCosmo() As Cosmopolitan.Presentation.Controls.OverflowControl
                Get
                    Dim root = System.Windows.Application.Current.RootVisual
                    Dim ribbonCosmo = FindControlByName(root, "CommandItems")
                    Return DirectCast(ribbonCosmo, Cosmopolitan.Presentation.Controls.OverflowControl)
                End Get
            End Property
    

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Monday, April 7, 2014 7:39 PM
  • Hi Dave,
    Don't know how to thank you enough.  That worked perfect and meant a lot to me, our project and company.  Without your help, this would not have been possible for me.  I am using a SQL query to access the Server Active Directory for User Authentication when signing on to our project.  This required a signon screen that has no menu/ribbon bar displayed until the User is authenticated.  Also, having our own nice front end "SignOn" screen, enabled the project to look more "welcome".  Thank you again...
    Ed
     
    PS: It was also a very nice contribution from you to the LightSwitch community. It will be useful, I'm sure...

    Edward Piccoli

    Tuesday, April 8, 2014 1:22 PM
  • Hi Edward,

    You are most welcome, continue the chain and help some other community members when you get the chance!

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Wednesday, April 9, 2014 8:10 AM