简体   繁体   English

WPF功能区遮盖了标题栏

[英]WPF Ribbon obscures the titlebar

I am making a WPF program in C# in Visual Studio 2013 and I am using the Ribbon component. 我正在Visual Studio 2013中用C#制作WPF程序,并且正在使用Ribbon组件。 So far I've only written XAML for the Ribbon and a few buttons on it, and have only modified the C# file by adding using System.Windows.Controls.Ribbon; 到目前为止,我只为功能区和其中的几个按钮编写了XAML,并且仅通过using System.Windows.Controls.Ribbon;添加修改了C#文件using System.Windows.Controls.Ribbon; and subclassing RibbonWindow instead of Window . RibbonWindow而不是Window I remembered to add a reference to the required .dll in Visual Studio for the Ribbon. 我记得在Visual Studio中为功能区添加了对所需.dll的引用。

When I run the program, the titlebar is really covered up: 当我运行程序时,标题栏确实被遮盖了: 在此处输入图片说明

Setting the Ribbon to have HorizontalAlignment="Left" makes it look like this: 将功能区设置为具有HorizontalAlignment="Left"使其看起来像这样: 在此处输入图片说明

I'm pretty new to WPF, C# and Visual Studio, so I don't have any idea what's wrong here. 我是WPF,C#和Visual Studio的新手,所以我不知道这里出了什么问题。 I have pasted my XAML code below (omitting the tab groups and application menu): 我在下面粘贴了我的XAML代码(省略了选项卡组和应用程序菜单):

<RibbonWindow
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Custom="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" x:Class="SwaagPaiNT.MainWindow"
        Title="Swaag PaiNT" Height="350" Width="525">
    <Grid>
        <Custom:Ribbon HorizontalAlignment="Stretch" VerticalAlignment="Top">
            <Custom:Ribbon.HelpPaneContent>
                <Custom:RibbonButton Name="what" ToolTip="whachunee" />
            </Custom:Ribbon.HelpPaneContent>

            <Custom:Ribbon.QuickAccessToolBar>
                <Custom:RibbonQuickAccessToolBar>
                    <Custom:RibbonButton x:Name="SAVE" ToolTip="BLAZE IT"/>
                    <Custom:RibbonSplitButton x:Name="Undo">
                        <Custom:RibbonSplitMenuItem Header="CANNOT UNDO MORE" />
                    </Custom:RibbonSplitButton>
                </Custom:RibbonQuickAccessToolBar>
            </Custom:Ribbon.QuickAccessToolBar>

        </Custom:Ribbon>

    </Grid>
</RibbonWindow>

This is a Windows 7 Professional 32-bit system. 这是Windows 7 Professional 32位系统。

But your problem is that everything is painted as it should be - Ribbon knows nothing about those close and minimize buttons - it is just given some space to be painted on. 但是您的问题是,所有内容均应按其原样进行绘制-Ribbon对那些关闭和最小化按钮一无所知-它仅提供了一些绘制空间。

To change its looks and behaviours either use templates , create a user control or directly subclass the Ribbon(it is not the usual way, but sometimes you really want to encapsulate your control). 要更改其外观和行为,请使用模板 ,创建用户控件或直接将Ribbon子类化(这不是通常的方法,但有时您确实希望封装控件)。

<Window>
   <Grid>
       ...
       <MyRibbon Grid.Row="0" .../>
       <Ribbon Grid.Row="1" Template={StaticResource MyRibbonTemplate} .../>
   </Grid>
</Windows>

EDIT: 编辑:

Sorry, I was a bit unattentive and never looked at RibbonWindow . 抱歉,我有点专心,没看过RibbonWindow I've actually never seen or used RibbonWindow. 我实际上从未见过或使用RibbonWindow。 What I've written before was nearly completely wrong. 我之前写的几乎是完全错误的。 Thank you for pointing it. 感谢您指出。 Now to the problem. 现在解决问题。

Such behaviour indicates that the Ribbon control is not integrated with the RibbonWindow as it should be, so you could: 这种现象表明Ribbon控件没有像应该的那样与RibbonWindow集成在一起,因此您可以:

  1. Try MSDN example in place of your code. 请尝试使用MSDN示例代替您的代码。 I don't see any fundamental differences, but who knows. 我看不出任何根本性的区别,但谁知道。 If it works - we will know that there is some simple problem in XAML or code-behind. 如果可行,我们将知道XAML或代码隐藏中存在一些简单的问题。 If not - try next 如果不是,请尝试下一个
  2. Try to change the targeted .NET version(Try the highest possible). 尝试更改目标.NET版本(尝试最高的版本)。
  3. Try to change the visual style in Windows(simplified to Aero or to Classic). 尝试更改Windows中的视觉样式(简化为Aero或Classic)。
  4. There are could be some problems with manually changed inheritance of your windows class to RibbonWindow . 将Windows类的继承手动更改为RibbonWindow可能存在一些问题。 Window's code-behind file is actually partial class. Window的代码隐藏文件实际上是部分类。 I am not sure how it may work in such a way, but that's a possible direction to look in. 我不确定它如何以这种方式工作,但这是一个可能的方向。

PS: I will give a try to it by myself later and write about any results. PS:我稍后会尝试一下,并写出任何结果。

EDIT: 编辑:

I've downloaded ribbon controls libraries and tried the MSDN example in Windows 8.1 with Visual Studio 2013 for .NET 4.5 - everything worked fine. 我已经下载了功能区控件库,并在Windows 8.1和.NET 4.5的Visual Studio 2013中尝试了MSDN示例-一切正常。 But when I changed the targeted framework to 4.0 the Ribbon control blackened the entire line with title. 但是,当我将目标框架更改为4.0时,Ribbon控件使标题的整个行变黑。 Nonetheless I'll try the example in Win 7 with VS2010. 尽管如此,我将在带有VS2010的Win 7中尝试该示例。

EDIT: 编辑:

Such code worked for me in Win7 VS2010 targeting .NET 4.0: 此类代码在针对.NET 4.0的Win7 VS2010中为我工作:

<ribbon:RibbonWindow x:Class="SwaagPaiNT.MainWindow"
        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"
        Title="MainWindow"
        x:Name="RibbonWindow"
        Width="640" Height="480">

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ribbon:Ribbon x:Name="Ribbon" Title="Ribbon Title">
            <ribbon:Ribbon.HelpPaneContent>
                <ribbon:RibbonButton />
            </ribbon:Ribbon.HelpPaneContent>
            <ribbon:Ribbon.QuickAccessToolBar>
                <ribbon:RibbonQuickAccessToolBar >
                    <ribbon:RibbonButton x:Name="QATButton1"/>
                    <ribbon:RibbonButton x:Name="QATButton2" 
                                         />
                </ribbon:RibbonQuickAccessToolBar>
            </ribbon:Ribbon.QuickAccessToolBar>
            <ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonApplicationMenu >
                    <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                      x:Name="MenuItem1"
                                                      />
                </ribbon:RibbonApplicationMenu>
            </ribbon:Ribbon.ApplicationMenu>
            <ribbon:RibbonTab x:Name="HomeTab" 
                              Header="Home">
                <ribbon:RibbonGroup x:Name="Group1" 
                                    Header="Group1">
                    <ribbon:RibbonButton x:Name="Button1"

                                         Label="Button1" />
                </ribbon:RibbonGroup>
            </ribbon:RibbonTab>
        </ribbon:Ribbon>
    </Grid>
</ribbon:RibbonWindow>

using Microsoft.Windows.Controls.Ribbon;

namespace SwaagPaiNT
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

The only real difference between your code and the shown above is in the 您的代码与上面显示的代码之间的唯一真正区别是

<RibbonWindow
 ...
 xmlns:Custom="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"

Your code uses xml schema to identify ribbon and not the clr-namespace as MSDN shows, also RibbonWindow is used without any namespace prefix. 您的代码使用xml模式来标识功能区,而不是MSDN所示的clr-namespace,而且RibbonWindow的使用没有任何名称空间前缀。

I hope that it will help. 我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM