How to Access and Change WPF-Ribbon Window Title Text Alignment
Categories: DotNetBar for WPF
Here is method that you can use to access and change the Ribbon Window text-alignment which is centered by default. Method access the reference to the Ribbon control that you placed on RibbonWindow.
C#:
private void ChangeRibbonTitleAlignment(Ribbon ribbonControl) { RibbonContentPanel contentPanel = ribbonControl.Template.FindName("PART_RCP", ribbonControl) as RibbonContentPanel; if (contentPanel != null) { foreach (UIElement item in contentPanel.Children) { if (item is RibbonBackgroundChrome) { TitlePanel panel = ((RibbonBackgroundChrome)item).Template.FindName("PART_TitleContent", (FrameworkElement)item) as TitlePanel; if (panel != null) { foreach (UIElement panelChild in panel.Children) { if (panelChild is Label && ((Label)panelChild).Name == "SysTitleLabel") { Label titleLabel = (Label)panelChild; titleLabel.HorizontalContentAlignment = HorizontalAlignment.Left; break; } } } break; } } } }
VB:
Private Sub ChangeRibbonTitleAlignment(ByVal ribbonControl As Ribbon) Dim contentPanel As RibbonContentPanel = TryCast(ribbonControl.Template.FindName("PART_RCP", ribbonControl), RibbonContentPanel) If contentPanel IsNot Nothing Then For Each item As UIElement In contentPanel.Children If TypeOf item Is RibbonBackgroundChrome Then Dim panel As TitlePanel = TryCast(DirectCast(item, RibbonBackgroundChrome).Template.FindName("PART_TitleContent", DirectCast(item, FrameworkElement)), TitlePanel) If panel IsNot Nothing Then For Each panelChild As UIElement In panel.Children If TypeOf panelChild Is Label AndAlso DirectCast(panelChild, Label).Name = "SysTitleLabel" Then Dim titleLabel As Label = DirectCast(panelChild, Label) titleLabel.HorizontalContentAlignment = HorizontalAlignment.Left Exit For End If Next End If Exit For End If Next End If End Sub
Related posts:
- How to create Backstage application menu in DotNetBar for WPF Ribbon Control
- How to access WPF Dock Floating Window
- How to Create WPF Navigation Pane Items Using Code
- How to re-use the brushes and colors used by Ribbon and other WPF controls
- How to build Office 2010 style Backstage application menu with DotNetBar for WPF
Leave a Reply!