如何在WPF功能区窗口(启用了Aero)中隐藏标题栏而没有隐藏的控制框? [英] How to hide Title bar in WPF Ribbon Window (Aero enabled) without hidden control box?

查看:328
本文介绍了如何在WPF功能区窗口(启用了Aero)中隐藏标题栏而没有隐藏的控制框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用WPF功能区窗口,并在当前窗口中启用Aero,如下图所示.我喜欢隐藏标题"Pattern Tester",因为没有足够的空间来显示它.但是我仍然需要原始的Windows控件框和当前标题(即使它会被隐藏),也可以在任务管理器和其他相关程序(如任务切换器和任务栏)中显示.

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标题栏的线程中下载源代码在RibbonWindow中难以阅读的文本.解决此问题的最简单方法是通过应用程序资源字典隐藏功能区标题面板控件.

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>

但是,功能区上下文"选项卡也被隐藏.为了解决此错误,我应该在加载当前窗口时将Ribbon Title Panel的Content Presenter的内容设置为空字符串.

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

剩下的问题,我不知道为什么不能在窗口onload事件中使用以下样式代替硬编码.

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>

这篇关于如何在WPF功能区窗口(启用了Aero)中隐藏标题栏而没有隐藏的控制框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆