XAML标记扩展
续更中...
x命名空间声明 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Static 用于检索静态值,其中包括常量、静态字段、静态属性、枚举值。注意:静态值更新了,属性值依然不会更新。
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public const string ConstA = "content";
public static string FieldB = "content";
public static string PropertyC { get; set; } = "content";
public string dddd;
public MainWindow()
{
InitializeComponent();
}
}
public enum EnumD
{
contentaa,
contentbb
}
private void Button_Click(object sender, RoutedEventArgs e)
{
FieldB = "我更新了";
}
}
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
Title="MainWindow">
<StackPanel>
<Button Content="{x:Static local:MainWindow.ConstA }" />
<Button Content="{x:Static local:MainWindow.FieldB }" />
<Button Content="{x:Static local:MainWindow.PropertyC }" />
<Button Content="{x:Static local:EnumD.contentaa}" />
<Button Content="更新值第二按钮值" Click="Button_Click"></Button>
</StackPanel>
</Window>
x:Type 指定类型,如果没有命名空间前缀,就取默认的,通常是 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"下的命名空间。
<Window.Resources>
<Style TargetType="{x:Type local:MyButton}"></Style>
<!--<Style TargetType="local:MyButton"></Style>-->
<Style TargetType="Button"></Style>
<!--<Style TargetType="{x:Type Button}"></Style>
<Style>
<Style.TargetType>
<x:Type TypeName="Button"></x:Type>
</Style.TargetType>
</Style>-->
</Window.Resources>
量变会引起质变。