Articles → LIGHT SWITCH 2011 → Hide menu and ribbon group in lightswitch 2011

Hide menu and ribbon group in lightswitch 2011


















Software requirement











Technical knowledge















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