【问题标题】:WPF: XAML namespaceWPF:XAML 命名空间
【发布时间】:2010-12-29 20:13:44
【问题描述】:

我在 AssemblyInfo.cs 中注册了一个程序集 XAML:

[assembly: XmlnsDefinition("http://schemas.mysite.es/wpf", "SWC.ViewModels")]

在我的命名空间中,我拥有这些类:

namespace SWC.ViewModels
{
    public class MenuViewModel 
        : ObservableCollection<MenuViewModel>
    {
        public MenuViewModel() 
            : base()
        {
        }
    }
}

如果我在用户控件 XAML 中使用命名空间,

<UserControl x:Class="SWC.UserControls.UserMenu"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:customMenu="http://schemas.mysite.es/wpf">

我可以在我的 XMLNS 命名空间中使用该类,

<UserControl.Resources>
        <customMenu:MenuViewModel x:Key="MenuItemsSource">

但是,当我执行应用程序时,编译器说

The label 'MenuViewModel' dosen't exist in the namespace XML 'http://schemas.mysite.es/wpf'

所有,可以帮助我吗?我被这个问题疯了!! 最好的问候,

【问题讨论】:

  • 欢迎来到 Stack Overflow!格式化提示:要获取代码块,请在每行前加上四个空格,或单击 {} 按钮。

标签: c# wpf xaml programming-languages


【解决方案1】:

我认为您需要指定您的 customMenu 控件所在的程序集。该程序集还必须从项目中引用(在“引用”部分中)。

xmlns:customMenu="clr-namespace:customMenuNamespace;assembly=customMenuLibrary"

否则我看不到编译器如何仅通过“http://schemas.mysite.es/wpf”找到您的实现。那个地址是什么?两个微软架构

http://schemas.microsoft.com/winfx/2006/xaml/presentation
http://http://schemas.microsoft.com/winfx/2006/xaml

像 xaml 编译器的一些标识符一样工作,这些地址没有任何内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多