XAML介绍
<phone:PhoneApplicationPage x:Class="HelloWorld.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
XAML是一种声明性标记语言,跟XML和HTML类似。xmlns:x声明一个命名空间,xmlns就是默认的命名空间。声明对象如果没有前缀的话就是引用默认的命名空间,否则就要指定命名空间下的对象。对象设置属性有4种方法:属性语法,属性元素语法,内容元素语法,集合语法。
属性语法:直接在对象里面设置属性 Width="20"
属性元素语法:在对象里面利用属性元素设置 <Ractangle.Fill><SolidColorBrush Color="Blue"/><Ractangle.Fill>
内容元素语法:<TextBlock>hello!</TextBlock>
集合语法:<LinearGradientBrush><GradientStop Offset="0.0" Color="Red" /><GradientStop Offset="1.0" Color="Blue" /></LinearGradientBrush>
XAML标记扩展使用{}框起来可以是数据绑定,StaticRrsource,TemplateBinding,RelativeSource。如下:
FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}"
例如在APP.xaml中定义全局样式。