可延伸應用程式標記語言 (XAML)eXtensible Application Markup Language (XAML)

XAML 是一種宣告式標記的語言,可用來定義使用者介面。使用 XAML 語法,雖然執行階段行為,被定義在個別的程式碼後置檔案中 XML 檔案中定義的使用者介面。XAML is a declarative markup language that can be used to define user interfaces. The user interface is defined in an XML file using the XAML syntax, while runtime behavior is defined in a separate code-behind file.

Evolve 2016: 成為 XAML MasterEvolve 2016: Becoming a XAML Master

注意

試試看XAML Standard 預覽版Try out the XAML Standard Preview

XAML 基本知識XAML Basics

XAML 可讓開發人員在 Xamarin.Forms 應用程式中使用標記,而不是程式碼定義使用者介面。XAML allows developers to define user interfaces in Xamarin.Forms applications using markup rather than code. Xamarin.Forms 程式永遠不會需要 XAML,但它是靈活,並經常會以視覺化方式一致且更簡潔,比對等的程式碼。XAML is never required in a Xamarin.Forms program but it is toolable, and is often more visually coherent and more succinct than equivalent code. XAML 是非常適合用於搭配熱門的 Model View ViewModel (MVVM) 應用程式架構: XAML 定義的檢視,透過以 XAML 為基礎的資料繫結連結到 ViewModel 的程式碼。XAML is particularly well suited for use with the popular Model-View-ViewModel (MVVM) application architecture: XAML defines the View that is linked to ViewModel code through XAML-based data bindings.

XAML 編譯XAML Compilation

XAML 可選擇性地使用 XAML 編譯器 (XAMLC) 直接編譯成中繼語言 (IL)。XAML can be optionally compiled directly into intermediate language (IL) with the XAML compiler (XAMLC). 此文章說明如何使用 XAMLC 和它的優點。This articles describes how to use XAMLC, and its benefits.

XAML 預覽程式XAML Previewer

XAML 預覽程式呈現頁面的並行以 XAML 標記,可讓您查看您呈現您所輸入的使用者介面的即時預覽。The XAML Previewer renders a live preview of a page side-by-side with the XAML markup, allowing you to see your user interface rendered as you type.

XAML 命名空間XAML Namespaces

XAML 使用xmlns命名空間宣告的 XML 屬性。XAML uses the xmlns XML attribute for namespace declarations. 本文介紹 XAML 命名空間語法,並示範如何宣告 XAML 命名空間,以存取的型別。This article introduces the XAML namespace syntax, and demonstrates how to declare a XAML namespace to access a type.

XAML 標記延伸XAML Markup Extensions

XAML 包含標記延伸模組,將屬性設定為 「 值 」 或 「 超出能使用簡單的字串表示的物件。XAML includes markup extensions for setting attributes to values or objects beyond what can be expressed with simple strings. 這些包括常數、 靜態屬性和欄位、 資源字典,以及資料繫結參考。These include referencing constants, static properties and fields, resource dictionaries, and data bindings.

欄位修飾詞Field Modifiers

x:FieldModifier命名空間屬性指定具名 XAML 項目產生欄位的存取層級。The x:FieldModifier namespace attribute specifies the access level for generated fields for named XAML elements.

傳遞引數Passing Arguments

XAML 可以用來將引數傳遞至非預設建構函式或 factory 方法中。XAML can be used to pass arguments to non-default constructors or to factory methods. 這篇文章示範如何使用可用來將引數傳遞至建構函式,呼叫 factory 方法,並指定的泛型引數類型的 XAML 屬性。This article demonstrates using the XAML attributes that can be used to pass arguments to constructors, to call factory methods, and to specify the type of a generic argument.

可繫結的屬性Bindable Properties

在 Xamarin.Forms 中,通用語言執行平台 (CLR) 屬性的功能會擴充可繫結的屬性。In Xamarin.Forms, the functionality of common language runtime (CLR) properties is extended by bindable properties. 可繫結的屬性是屬性的特殊類型,其中 Xamarin.Forms 屬性系統會追蹤屬性的值。A bindable property is a special type of property, where the property's value is tracked by the Xamarin.Forms property system. 這篇文章介紹可繫結的屬性,並示範如何建立和使用它們。This article provides an introduction to bindable properties, and demonstrates how to create and consume them.

附加屬性Attached Properties

附加的屬性是特殊類型的可繫結的屬性,定義一個類別中,但連接至其他物件,並可辨識在 XAML 做為屬性中包含的類別,以句號分隔屬性名稱。An attached property is a special type of bindable property, defined in one class but attached to other objects, and recognizable in XAML as an attribute that contains a class and a property name separated by a period. 本文章提供附加屬性的簡介,並示範如何建立和使用它們。This article provides an introduction to attached properties, and demonstrates how to create and consume them.

資源字典Resource Dictionaries

XAML 資源都可以使用一次以上的物件的定義。XAML resources are definitions of objects that can be used more than once. A ResourceDictionary 允許在單一位置中,定義及重複使用在 Xamarin.Forms 應用程式的資源。A ResourceDictionary allows resources to be defined in a single location, and re-used throughout a Xamarin.Forms application. 這篇文章示範如何建立及取用ResourceDictionary,以及如何合併其中ResourceDictionary到另一個。This article demonstrates how to create and consume a ResourceDictionary, and how to merge one ResourceDictionary into another.