简体   繁体   中英

WPF: XAML namespace

I have one assembly XAML registered in AssemblyInfo.cs:

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

And In my namespace I hace these classes:

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

If I use the namespace in a user control 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">

I can use the class in my XMLNS namespace,

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

But, when I execute the application, the compiler said

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

All, can help me?? I'm crazy with this problem!! Best regards,

I think you need to specify the assembly in which your customMenu controls exist. The assembly must also be referenced from the project (in the References section).

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

Otherwise I don't see how the compiler can find your implementation only through "http://schemas.mysite.es/wpf". What's at that address? The two microsoft schemas

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

work like some identifiers for the xaml compiler, there is nothing at those addresses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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