Question

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

Was it helpful?

Solution

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>

OTHER TIPS

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;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top