【问题标题】:The tag 'Ribbon' does not exist in XML namespaceXML 命名空间中不存在标记“功能区”
【发布时间】:2012-05-22 18:15:59
【问题描述】:

我正在尝试在 .Net 4.5 框架上使用功能区控件开发 WPF 应用程序。 据我所知,MSDN Ribbon Class 现在已包含在 Net 4.5 框架中,因此,我不再需要添加 this。

但是当我尝试添加这段代码时:

<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

【问题讨论】:

    标签: c# wpf ribbon


    【解决方案1】:

    您需要添加对 System.Windows.Controls.Ribbon.dll 的引用(它是 .NET 4.5 框架的一部分。然后您需要将命名空间添加到您的 XAML,例如:

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

    到你的窗口获取命名空间,然后你可以像使用它

    <ribbon:Ribbon ... />
    

    就像科尔·约翰逊所说的那样。

    这是MSDN reference on the Ribbon class,它显示了所有这些信息。

    【讨论】:

    • xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon" 抛出错误 1 ​​命名空间“System.Windows.Controls”中不存在类型或命名空间名称“功能区”(您是否缺少程序集引用?) C:\tmp\ tst2\tst2\obj\Debug\MainWindow.g.cs 18 31 tst2 错误。太诡异了。
    • 好吧,如果您使用的是 .NET 4.5,它肯定存在:msdn.microsoft.com/en-us/library/… - 您是否引用了 System.Windows.Controls.Ribbon DLL?
    • 我在想我不需要引用 DLL,因为它是框架的一部分。感谢您的帮助。
    【解决方案2】:

    是

    还需要参考功能区的方案

    【讨论】:

    • 我检查了using System.Windows.Controls.Ribbon; 也不起作用。
    • @noway 这就是您在 C# 代码中引用它的方式。但是您需要在 XAML 中访问它。所以你需要添加命名空间。
    猜你喜欢
    • 2011-10-11
    • 1970-01-01
    • 2014-04-19
    • 2020-10-13
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多