名稱 | 種類(默認Attribute) | 備註 |
---|---|---|
x:Array | 標籤拓展 | 可做爲 ListBox.ItemsSource 的值 |
x:Class | 指定與 .cs 中哪一個類合併,所指示的類型在聲明時使用 partial 關鍵字 | |
x:ClassModifier | 指定標籤編譯生成的類具備怎樣的訪問控制級別,跟類型的訪問級別要一致 public、internal | |
x:Code | XAML 指令元素 | 把代碼後置的 C# 代碼寫到 xaml 中 |
x:FieldModifier | 當從一個程序集訪問另外一個程序集的窗體的元素時,就須要把被訪問控件的引用變量改成 public 級別 | |
x:Key | 標註資源,其餘地方能夠經過 key 值找到這個資源 | |
x:Name | 標註標籤,其餘標籤或後置代碼能夠經過 Name 值找到這個資源 | |
x:Null | 標籤拓展 | 表示空值,通常用於有默認值可是又不須要這個默認值時。如:Sytle="{x:Null}" |
x:Shared | 默認爲 true,與 x:key 一塊兒配合使用,表示調用資源時是否每次獲得的都是同一個對象。 | |
x:Static | 標籤拓展 | 調用某個類的靜態屬性 |
x:Subclass | ||
x:Type | 標籤拓展 | 1)編程層面:數據類型,建立對象時開闢相應大小的內存;2)邏輯層面:抽象和封裝的結果 |
x:TypeArguments | ||
x:Uid | 元素的惟一標識符 | |
x:XData | XAML 指令元素 | 用於資源中的 XmlDataProvider 標籤 |
public class MyButton : Button { public Type UserWindowType { get; set; } protected override void OnClick() { base.OnClick(); Window win = Activator.CreateInstance(this.UserWindowType) as Window; if (win != null) { win.ShowDialog(); } } } <Window x:Class="WpfApp1.CommandMode.MyWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1.CommandMode" mc:Ignorable="d" Title="MyWindow" Height="450" Width="800"> <Grid Background="Yellow"> </Grid> </Window> <!--把 MyWindow 做爲一種數據類型賦值給 MyButton.UserWindowType--> <local:MyButton UserWindowType="{x:Type local:MyWindow}" Content="OpenMyWindow"/>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}"> </Style>
x:Null、x:Type 兩個標記拓展通常用更簡潔的方式即用花括號括起來的字符串做爲值賦給標籤 Attribute 的形式。但 x:Array 必須用標記拓展的方式。express
<Window ... xmlns:sys="clr-namespace:System;assembly=mscorlib"> </Window> <!--若是是簡潔寫法:並不能給 ArrayExtension 的 只讀屬性 Items 賦值--> <ListBox ItemsSource="{x:Array Type=sys:String}"/> <!--正確寫法--> <ListBox> <ListBox.ItemsSource> <x:Array Type="{x:Type sys:String}"> <sys:String>hallo1</sys:String> <sys:String>hallo2</sys:String> <sys:String>hallo3</sys:String> </x:Array> </ListBox.ItemsSource> </ListBox> <!--等同於--> <ListBox> <ListBox.Items> <sys:String>hallo1</sys:String> <sys:String>hallo2</sys:String> <sys:String>hallo3</sys:String> </ListBox.Items> </ListBox>
<Window.Resources> <XmlDataProvider x:Key="XMlData"> <x:XData> <Super xmlns=""> <Colors> <Color>紅</Color> <Color>綠</Color> <Color>黃</Color> </Colors> <Sexs> <Sex>男</Sex> <Sex>女</Sex> </Sexs> </Super> </x:XData> </XmlDataProvider> </Window.Resources> <StackPanel> <!--紅綠黃各一行--> <ListBox ItemsSource="{Binding Source={StaticResource XMlData}, XPath=/Super/Colors/Color}"> <!--男女各一行--> <ListBox ItemsSource="{Binding Source={StaticResource XMlData}, XPath=/Super/Sexs/Sex}"> <!--紅綠黃男女總共一行--> <ListBox ItemsSource="{Binding Source={StaticResource XMlData}, XPath=/Super}"> </StackPanel>