名称 | 种类(默认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>