Reading this article in MSDN forums and taking the best (I hope) of what LR_ and Michael Washington offered as solutions I ended up with an extension class that allows you to put your application’s logo on the Ribbon Bar of any shell having one. You also have the choice to put it either on the left or the right. LR_’s original code was only modified in 2 points.
Although implied from the detailed reference to them I want to thank both guys for making it so easy for me to put my logo on screen.
- You can decide if you want you Application Logo on the left or on the right of your commands.
- You don’t need to pass a URL to the image. The application’s logo (defined in project properties) is bound inspired by the XAML provided by Michael Washington.
Although implied from the detailed reference to them I want to thank both guys for making it so easy for me to put my logo on screen.
private static class LogoPlacement { public static void AddLogo(this Microsoft.LightSwitch.Client.IClientApplication application, System.Windows.HorizontalAlignment alignment) { Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() => { LogoPlacement.AddLogo(System.Windows.Application.Current.RootVisual, alignment); }); } internal static void AddLogo(UIElement element, System.Windows.HorizontalAlignment alignment) { 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(child, alignment); } 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") }); myImage.MouseLeftButtonUp += (s, e) => MessageBox.Show("Here may be some About..."); 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); } } private static RibbonCommandBar rcb = null; }