How to hide Title bar in WPF Ribbon Window (Aero enabled) without hidden control box?

☆樱花仙子☆ 提交于 2019-12-21 05:14:07

问题


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.


回答1:


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>

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 = "";
    }
}

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>



回答2:


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;



来源:https://stackoverflow.com/questions/6825139/how-to-hide-title-bar-in-wpf-ribbon-window-aero-enabled-without-hidden-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!