Articles → LIGHT SWITCH 2011 → Hide Menu And Ribbon Group In Lightswitch 2011

Hide Menu And Ribbon Group In Lightswitch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.

Technical Knowledge




  1. How to create projects in visual studio?
  2. How to create screens in lightswitch?
  3. What is screen's run event?
  4. What do you mean by visual parent (or child) of an element in Silverlight?
  5. What is the purpose of application.cs file?

Create A New Project And Add A New Screen




Picture showing the design screen of the editable grid screen
Click to Enlarge



Picture showing the default menu of the lightswitch application
Click to Enlarge


Write Code To Hide Controls




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

namespace LightSwitchApplication.UserCode {
	public class RibbonAndMenuClass {

		private static DependencyObject FindControlByName(DependencyObject control, string name) {
			if (control.GetValue(FrameworkElement.NameProperty) != null && control.GetValue(FrameworkElement.NameProperty).ToString() == name) {
				return control;
			}

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

		public static void HideRibbonAndMenu() {
			Dispatchers.Main.Invoke(() = >{
				UIElement root = System.Windows.Application.Current.RootVisual;
				((NavigationView) FindControlByName(root, "NavigationView")).Visibility = Visibility.Collapsed;
				((RibbonCommandBar) FindControlByName(root, "HomeTabItem")).Visibility = Visibility.Collapsed;
			});
		}
	}
}



Call The Method From Screen’S Run Method




Picture showing adding the EditableGrid_Run event in the screen
Click to Enlarge



using LightSwitchApplication.UserCode;
namespace LightSwitchApplication {
	public partial class Application {

		partial void EditableGrid_Run(ref bool handled) {
			RibbonAndMenuClass.HideRibbonAndMenu();
		}
	}
}





Output


Picture showing the default menu hidden in the lightswitch application
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, October 24, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250