[英]WPF: XAML namespace
我在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'
所有,可以幫助我嗎? 我為這個問題瘋狂! 最好的祝福,
我認為您需要指定customMenu控件所在的程序集。 程序集也必須從項目中引用(在“引用”部分中)。
xmlns:customMenu="clr-namespace:customMenuNamespace;assembly=customMenuLibrary"
否則,我看不到編譯器如何只能通過“ http://schemas.mysite.es/wpf”找到您的實現。 那地址是什么? 兩種Microsoft模式
http://schemas.microsoft.com/winfx/2006/xaml/presentation
http://http://schemas.microsoft.com/winfx/2006/xaml
就像xaml編譯器的某些標識符一樣工作,這些地址沒有任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.