首页 > 编程知识 正文

西安马拉松,寻爱魔力

时间:2023-05-03 06:45:11 阅读:216589 作者:961


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属性的,

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。