Articles → LIGHT SWITCH 2011 → Hide Menu And Ribbon Group In Lightswitch 2011
Hide Menu And Ribbon Group In Lightswitch 2011
Software Requirement
 
- Visual studio 2010 is installed on your machine.
 - Visual Studio 2010 service pack 1 is installed on your machine.
 - Microsoft Visual Studio Light switch 2011 is installed on your machine.
 
Technical Knowledge
 
- How to create projects in visual studio?
 - How to create screens in lightswitch?
 - What is screen's run event?
 - What do you mean by visual parent (or child) of an element in Silverlight?
 - What is the purpose of application.cs file?
 
Create A New Project And Add A New Screen
 
Click to Enlarge
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
 
Click to Enlarge
using LightSwitchApplication.UserCode;
namespace LightSwitchApplication {
	public partial class Application {
		partial void EditableGrid_Run(ref bool handled) {
			RibbonAndMenuClass.HideRibbonAndMenu();
		}
	}
}
Output
 
Click to Enlarge
| Posted By  -   | Karan Gupta | 
|   | 
| Posted On  -   | Friday, October 24, 2014 |