xaml


1.认识xaml

xaml是一种声明式的语言,当你看到一个标签,就意味着声明了一个对象,
对象之间的关系要么式并列,要么式包含,全都体现到标签的关系。

Property 属性
Attribute 属性 
前者侧重对象的属性,后侧侧重xml 文法属性,通常来说,后者的数量多于前者。

<Window x:Class="WpfApp1.MainWindow"
        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"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel>
            <Button Content="测试" Width="100" Height="20"  x:Name="btn1"  ></Button>
            <Button Content="你好" Width="100" Height="20"  x:Name="btn2" IsEnabled="{Binding State}"></Button>
        
        </StackPanel>

    </Grid>
</Window>

window 对象的Height是Property,Class 是xml文法上的属性。


xaml的名称空间

c# 名称空间使用using语法,xaml 使用 xmlns语法。
xmlns[:可选的映射前缀] = "名称空间" 

引用程序集的命名空间:
 xmlns:test="clr-namespace:System.Data;assembly=System.Data"
 

如何自定义URL
Properties
AssemblyInfo.cs 
[assembly: XmlnsDefinition("http://www.Test.com", "WpfApp1.Test1")]
[assembly: XmlnsDefinition("http://www.Test.com", "WpfApp1.Test2")]
[assembly: XmlnsDefinition("http://www.Test.com", "WpfApp1.Test3")]

xmal 引入命名空间有2种,一种是http的字符串,这个字符串对应的命名空间已经在AssemblyInfo确定了。
一种是单个命名空间,clr-namespace assembly 格式,指出引用的命名空间和程序集的名称。

2.xaml


如果属性是一个复杂元素,而不是一个简单的字符串,则属性的值是一个元素。

<Rectangle.Fill>
<SolidColorBrush Color="red" ></SolidColorBrush>
</Rectangle.Fill>

标记扩展
<StackPanel>
            <Button Width="60" Content="测试" x:Name="btn"></Button>
            <TextBlock Text="{Binding ElementName=btn, Path=Width}"></TextBlock>
        </StackPanel>

比如绑定


xaml 标签的属性

x 命名空间的都是http://schemas.microsoft.com/winfx/2006/xaml 携带的命名空间
常用的有
x:Class 类名
x:Key 键
x:Name 控件的名称
X:Null 空对象
X:Static 静态的
X:Type 类型

X:Name 和Name 的区别
Name 是FramwWorkElement 类的属性,这个是wpf的基类,所有的wpf控件都具有此属性。
有些类是没有的Name属性的,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值