开发者

WPF: XAML namespace

I have one assembly XAML registered in AssemblyInfo.cs:

[assembly: XmlnsDefinition("http://schemas.mysite.es/wpf", "SWC.ViewModels")]
开发者_StackOverflow社区

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜