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