“Ribbon”标记在XML命名空间中不存在。

3
我正在尝试在.Net 4.5框架上开发一个带有Ribbon控件的WPF应用程序。据我所知,MSDN Ribbon Class现在已经包含在Net 4.5框架中,因此我不需要再添加这个了。
但是当我尝试添加以下代码时:
<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <Ribbon>
        </Ribbon>
    </StackPanel>
</Window>

我遇到了以下错误。我是否漏掉了什么?
The tag 'Ribbon' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

编辑:

using System.Windows.Controls.Ribbon;

也不起作用。

The type or namespace name 'Ribbon' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)  c:\tmp\tst2\tst2\MainWindow.xaml.cs
2个回答

4

您需要添加对System.Windows.Controls.Ribbon.dll的引用(它是.NET 4.5框架的一部分)。然后,您需要在XAML中添加命名空间,类似于:

xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"

打开您的窗口以获取命名空间,然后可以像这样使用它

<ribbon:Ribbon ... />

就像Cole Johnson所说的那样。

这是Ribbon类的MSDN参考文档,其中展示了所有相关信息。


xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon" 抛出错误1:命名空间'System.Windows.Controls'中不存在类型或命名空间名称'Ribbon'(是否缺少程序集引用?) C:\tmp\tst2\tst2\obj\Debug\MainWindow.g.cs 18 31 tst2,这太奇怪了。 - noway
如果你正在使用.NET 4.5,那么它肯定在这里:http://msdn.microsoft.com/en-us/library/system.windows.controls.ribbon.ribbon(v=vs.110) - 你是否引用了System.Windows.Controls.Ribbon DLL? - Tim
我曾认为不需要引用DLL,因为它是框架的一部分。感谢您的帮助。 - noway

0

这是<ribbon:Ribbon />

同时您需要引用该功能区的方案


我检查了using System.Windows.Controls.Ribbon;也不起作用。 - noway
@noway 这是你在 C# 代码中引用它的方式。但你需要在 XAML 中访问它。因此,你需要添加命名空间。 - Tim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接