When you buy this book you support this site! - Thank You for your support!
Written by: kchristo Thursday, July 12, 2012
public static void AddLogo(this Microsoft.LightSwitch.Client.IClientApplication application, System.Windows.HorizontalAlignment alignment, string screenName) { Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() => { LogoPlacement.AddLogo(application, System.Windows.Application.Current.RootVisual, alignment, screenName); });}private static class LogoPlacement{ internal static void AddLogo(Microsoft.LightSwitch.Client.IClientApplication application, UIElement element, System.Windows.HorizontalAlignment alignment, string screenName) { if (rcb != null) return; for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(element); i++) { if (rcb != null) return; UIElement child = (UIElement)System.Windows.Media.VisualTreeHelper.GetChild(element, i); AddLogo(application, child, alignment, screenName); } if (element is Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.RibbonCommandBar) { rcb = element as Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard.RibbonCommandBar; Image myImage = new Image() { Stretch = System.Windows.Media.Stretch.Uniform, Margin = new Thickness(2, 8, 14, 8), HorizontalAlignment = alignment, Cursor = System.Windows.Input.Cursors.Hand }; myImage.SetValue(ComponentViewModelService.ViewModelNameProperty, "Default.LogoViewModel"); myImage.SetBinding(Image.SourceProperty, new System.Windows.Data.Binding { Path = new PropertyPath("Logo") }); if (!string.IsNullOrWhiteSpace(screenName)) myImage.MouseLeftButtonUp += (s, e) => { application.Details.Dispatcher.BeginInvoke(() => application.Details.Methods[string.Format("Show{0}", screenName)].CreateInvocation().Execute()); }; myImage.SizeChanged += (s, e) => { double left = (s as Image).HorizontalAlignment == HorizontalAlignment.Left ? e.NewSize.Width + 10.0 : 0.0; double right = (s as Image).HorizontalAlignment == HorizontalAlignment.Right ? e.NewSize.Width + 10.0 : 0.0; rcb.Padding = new Thickness(left, 0, right, 0); }; ((Grid)rcb.Parent).Children.Add(myImage); } }
0 comment(s) so far...