Window、Grid、TextBox、Button等,都叫元素

xaml文檔中,<>用來定義標籤,標籤可以用來描述元素或元素的屬性,如:

<Window>
    <Window.Resources>
    </Window.Resources>
  </Window>


Window是元素,Resources是Window的一個屬性

標籤內容可以包含其他元素的標籤,如
  

<Window>
    <Grid>
      <Button />
    </Grid>
  </Window>


有些元素只能包含一個子元素,有些能包含很多子元素。

每個元素都可以有屬性,如
  

<Window>
    <Grid>
      <Button Height = "30"/>
    </Grid>
  </Window>

描述元素的屬性還可以用屬性標籤的方式來寫

<Window>
    <Grid>
      <Button>
        <Button.Height>40</Button.Height>
      </Button>
    </Grid>
  </Window>


屬性標籤更有層次,但超級囉嗦,沒有使用的必要

屬性的值可以是字符串,也可以用標記擴展的形式完成類似綁定數據等複雜的操作。
  

<Window>
    <Grid>
      <TextBox Text ="{Binding ElementName= slider1, Path=Value, Mode=OneWay}"/>
      <Slider Height="19" Name="slider1" Width="139" />
    </Grid>
  </Window>

用屬性標籤的寫法,可以寫成這樣

<TextBox.Text>
    <Binding ElementName ="slider1" Path ="Value" Mode="OneWay"/>
   </TextBox.Text>


這種寫法在vs2010下很不給力,智能提示不到位……

屬性不僅可以是元素自身的,也可以是其他元素的屬性
引用其他元素屬性的用法叫做附加屬性,被引用的元素必須要寫明所在的命名空間前綴
 

<Window>
    <Grid>
      <Button x:Name = "btn1" Grid.Row = "2"/>
    </Grid>
  </Window>

Grid.Row沒有前綴?那是因為有個默認的命名空間xmlns,使用它包含的類時就不用寫明命名空間前綴

命名空間在根元素的屬性中定義

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="App1.Window3">  </Window>

xmlns定義的即是默認的命名空間,這裏把它指向了WPF所有的控件類。
xmlns:x 定義了另一個命名空間,這裏的x叫做命名空間前綴,理解成簡稱也可以。
x:Class 是附加屬性,指明後置代碼中的cs類名稱

x命名空間下的類用途亂七八糟的,記住名字就行
  x:Name
  x:Class
  x:Subclass
  x:Type
  x:Null
  x:Key
  x:Array
  x:Static
  x:Shared

  x:Code
  x:XData

xmal 是標記語言,如同html一樣。類似Jquery,.net也提供了兩個幫助類:VisualTreeHelper、LogicalTreeHelper