开发者

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

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 t开发者_开发知识库o 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.

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


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>

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

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

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

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>


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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜