Zhou 的个人资料Sheva's TechSpace照片日志列表 工具 帮助
2006/8/28

XmlnsDefinitionAtrribute Is Pretty Nifty

    When we want to declaratively use our custom controls or reference the types we defined in XAML, we should declare the XML namespace to map to the CLR namespace in which the controls and types are defined as the following XAML snippt demonstrates:

<Page x:Class="Test.MainWindow"
         xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:cc
="clr-namespace:Sheva.Windows.Controls;assembly=AvalonLib"
/>

    Recently, I am heavily engaged with writing a resuable WPF control library, and quite often I need to create some pages to test those controls I create, so ever now and then I have to use the cumbersome syntax like above to declare the XML namespace, personally I don't like the syntax, and I thought Microsoft WPF team should come up with a more elegant way of doing it, and in actuality, they did introduce an alternative to do it since the CTP releases. there is a custom attribute called XmlnsDefinitionAttribute in the System.Windows.Markup namespace which allows you to apply to the assembly which contains the types and controls the XAML code would reference.the built-in WPF assemblies such as WindowsBase.dll, PresentationCore.dll, and PresentationFramework.dll all have this attribute applied, and all have http://schemas.microsoft.com/winfx/2006/xaml/presentation XML namespace mapped with the CLR namespaces introduced by them. and of cause you can use this attribute in your own project, just open the AssemblyInfo.cs file, and append the following directive:

[assembly: XmlnsDefinition("http://schemas.sheva.com/wpf/""Sheva.Windows.Controls")]

    Then you can declare the namespace alias in XAML this way:

<Page x:Class="Test.MainWindow"
         xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:cc
="http://schemas.sheva.com/wpf/"
/>
   
    Wow, this is a bit like the built-in xmlns declaration indeed, really really cool indeed:)

评论 (9)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。
YongZhou 在此页禁用了评论功能。
6 月 27 日
没有名字发表:

包茎など男の悩み相談なら泌尿器科包茎手術形成外科 の大阪梅田中央クリニック

6 月 27 日
6 月 27 日
6 月 27 日
6 月 27 日
6 月 24 日
没有名字发表:
wow gold wow gold wow power leveling wow power leveling wow gold@@@@ World of Warcraft Gold wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow powerleveling wow powerleveling wow powerleveling rolex replica wow powerleveling wow powerleveling wow powerleveling wow powerleveling wow powerleveling wow powerleveling wow powerleveling wow powerleveling replica rolex powerleveling powerleveling powerleveling powerleveling power leveling power leveling powerleveling powerleveling power leveling power leveling power leveling power leveling power leveling power leveling power leveling power leveling rolex wow gold wow gold Warcraft Gold Warcraft Gold 中高年 転職 アルバイト 求人情報 ブライダル 転職 競馬 FX ダイエット お見合い 競馬 予想 新築マンション 新築マンション コンタクトレンズ 婚約指輪 合宿免許 人材派遣 東京都 墓地 派遣会社 人材派遣 パチンコ 攻略 おなら 货架 OCR OCR 手机词典 高速扫描 机票 灭蟑螂 蜗轮减速机 减速机 齿轮减速机 丝杆升降机 租房 租房 北京租房 北京租房 搬家公司 北京搬家 北京搬家公司 上海机票 上海机票 上海打折机票 上海打折机票 上海特价机票 上海特价机票 搬家公司 搬家公司 北京搬家公司 北京搬家公司 窃听器 窃听器 手机窃听器 手机窃听器 代孕 试管婴儿 捐卵 代孕 fgdfhhmbmbnm
1 月 13 日
YongZhou发表:
  Actually, those xml namespaces are URI or URL based, the reason why the URIs are choosed is basically because URIs have little chance of naming confliction, butthose URIs designating xml namespace doesn't necessarily point to the real resources on the web.
Sheva 
9 月 9 日
没有名字发表:
A novice question: will these namespace id URIs sometimes point to real net resources? Or this is just a little bit strange xml-fashion of namespace id naming?
9 月 7 日

引用通告 (1)

此日志的引用通告 URL 是:
http://shevaspace.spaces.live.com/blog/cns!FD9A0F1F8DD06954!420.trak
引用此项的网络日志