WPF學習系列004: 2.3 命名空間

 

2.3 命名空間

  1. XAML文件的根對象元素必須指定至少一個XML命名空間,用於驗證自己和子元素。
  2. 命名空間的使用:xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentatio"
  3. 可以(在根元素或子元素上)聲明額外的XML命名空間,但每一個命名空間下的標識符都必須有一個唯一的前綴。
  4. 次要命名空間的使用:xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml"
  5. http://schemas.microsoft.com/winfx/2006/xaml/presentatio 作爲默認(主要)命名空間。
  6. http://schemas.microsoft.com/winfx/2006/xaml 作爲次要命名空間,次要命名空間的前綴是x
  7. 例如:

<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Background="{x:Null}"

Height="{x:Static SystemParameters.IconHeight}"

Content="{Binding Path=Height, RelativeSource={RelativeSource Self}}" />

其中:xmlns 特性是主命名空間,默認情況下,變量引用使用默認空間的類

xmlns:x 特性是次命名空間,其前綴爲 x ,所有引用次命名空間的類型需要加上次命名空間前綴,如 x:Nullx:Static SystemParameters.IconHeight

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章