4

I currently use WPF Ribbon Window and enable Aero in current window like the following photo. I like to hide title that is "Pattern Tester" because there is not enough of space to show it. But I still need original windows control box and current title (even it will be hidden) that will be shown in task manager and other ralated program like task switcher and taskbar.

WPF Ribbon Window

2 Answers2

5

I accidentally found the answer for this question when I read & download source code in thread about WPF Title Bar Text Hardly Readable in RibbonWindow. The easiest way to solve this problem is just hidden Ribbon Title Panel control via application resource dictionary.

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            xmlns:ribbonPre="clr-namespace:Microsoft.Windows.Controls.Ribbon.Primitives;assembly=RibbonControlsLibrary">
    <Style TargetType="{x:Type ribbonPre:RibbonTitlePanel}">
        <Setter Property="Visibility" Value="Hidden"/>
    </Style>
 </ResourceDictionary>

enter image description here

However, the Ribbon Contextual Tab is also hidden. For fixing this bug, I should set the content of Content Presenter of Ribbon Title Panel to empty string when current window is loaded.

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var titlePanel = Ribbon.Template.FindName("PART_TitleHost", Ribbon) as ContentPresenter;
    if (titlePanel != null)
    {
        titlePanel.Content = "";
    }
}

enter image description here

The remaining question, I don't know why I cannot the following style instead of hardcode in window onload event.

<Style TargetType="{x:Type ribbonPre:RibbonTitlePanel}">
    <Setter Property="ContentPresenter.Content" Value=""/>
</Style>
user229044
  • 232,980
  • 40
  • 330
  • 338
3

In the Load event of the window, add the next line:

((System.Windows.UIElement)((System.Windows.FrameworkElement)(this.RibbonMain.Template.FindName("PART_TitleHost", this.RibbonMain) as ContentPresenter).Parent).Parent).Visibility = Visibility.Collapsed;

  • I'm using the ribbon on a UserControl and I needed to get rid of the ribbons title area also. Tried the xaml above but it couldn't find the RibbonTitlePanel in ribbonPre. So I scrapped that and tried this. One single line of code in the UserControl Loaded event. Works like a charm! Thanks! – tolsen64 Jul 05 '18 at 06:58