星空网 > 软件开发 > ASP.net

WPF学习(一) - XAML

Window、Grid、TextBox、Button等,都叫元素

xaml文档中,<>用来定义标签,标签可以用来描述元素或元素的属性,如:
  <Window>
    <Window.Resources>
    </Window.Resources>
  </Window>
Window是元素,Resources是Window的一个属性

标签内容可以包含其他元素的标签,如
  <Window>
    <Grid>
      <Button />
    </Grid>
  </Window>
有些元素只能包含一个子元素,有些能包含很多子元素。

每个元素都可以有属性,如
  <Window>
    <Grid>
      <Button Height = "30"/>
    </Grid>
  </Window>

描述元素的属性还可以用属性标签的方式来写
  <Window>
    <Grid>
      <Button>
        <Button.Height>40</Button.Height>
      </Button>
    </Grid>
  </Window>
属性标签更有层次,但超级啰嗦,没有使用的必要

属性的值可以是字符串,也可以用标记扩展的形式完成类似绑定数据等复杂的操作。
  <Window>
    <Grid>
      <TextBox Text ="{Binding ElementName= slider1, Path=Value, Mode=OneWay}"/>
      <Slider Height="19" Name="slider1" Width="139" />
    </Grid>
  </Window>

用属性标签的写法,可以写成这样
  <TextBox.Text>
    <Binding ElementName ="slider1" Path ="Value" Mode="OneWay"/>
   </TextBox.Text>
这种写法在vs2010下很不给力,智能提示不到位……

属性不仅可以是元素自身的,也可以是其他元素的属性
引用其他元素属性的用法叫做附加属性,被引用的元素必须要写明所在的命名空间前缀
  <Window>
    <Grid>
      <Button x:Name = "btn1" Grid.Row = "2"/>
    </Grid>
  </Window>

Grid.Row没有前缀?那是因为有个默认的命名空间

命名空间在根元素的属性中定义
  <Window ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    ="http://schemas.microsoft.com/winfx/2006/xaml"
    x:>

  </Window>

x:Class 是附加属性,指明后置代码中的cs类名称

x命名空间下的类用途乱七八糟的,记住名字就行
  x:Name
  x:Class
  x:Subclass
  x:Type
  x:Null
  x:Key
  x:Array
  x:Static
  x:Shared

  x:Code
  x:XData

xmal 是标记语言,如同html一样。类似Jquery,.net也提供了两个帮助类:VisualTreeHelper、LogicalTreeHelper

 




原标题:WPF学习(一) - XAML

关键词:wpf

wpf
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

湃势:https://www.ikjzd.com/w/1573203600868810754
PIX 支付:https://www.ikjzd.com/w/1573203602991128578
PixelYourSite:https://www.ikjzd.com/w/1573203608020099074
貔貅兔erp:https://www.ikjzd.com/w/1573203608628273154
Play:https://www.ikjzd.com/w/1573203616815898625
plentymarkets:https://www.ikjzd.com/w/1573203618946260994
企业家的10个创新科技商业理念:https://www.kjdsnews.com/a/1842119.html
长白山有什么特色小吃呢:https://www.vstour.cn/a/407245.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流