首页 技术 正文
技术 2022年11月12日
0 收藏 586 点赞 4,914 浏览 1890 个字

在WPF中引入了XAML语言,主要用于界面设计,业务逻辑则使用C#实现后台代码,将界面设计与业务逻辑分离

XAML是一种声明式语言,类似XML\HTML

示例:

<!–Start Tag–>

<Button xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” Width=”300″ Height=”200″>
  <!–Property–>
  <Button.Content>
    Hello XAML
  </Button.Content>
</Button>
<!–End Tag–>

这是一个普通的Button

<DockPanel>
  <Button DockPanel.Dock=”Left” Background=”AliceBlue” Margin=”0,5,0,10″ Content=”Hello XAML” />
  <Button DockPanel.Dock=”Right”>
    <Button.Background>
      <LinearGradientBrush StartPoint=”0,0″ EndPoint=”1,1″>
        <GradientStop Color=”Yellow” Offset=”0.0″ />
        <GradientStop Color=”Green” Offset=”0.25″ />
        <GradientStop Color=”Blue” Offset=”0.75″ />
        <GradientStop Color=”LimeGreen” Offset=”1″ />
      </LinearGradientBrush>
    </Button.Background>
    Hello XAML
  </Button>
</DockPanel>

在面板(DockPanel)窗口中有两个Button

XAML有两个重要组成:完整的开始/结束标签,即元素;依赖于元素的要素,即属性

命名空间

WPF命名空间 xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

XAML至少要指定一个命名空间,为了作用于整个文件,通常放置在根元素中

WPF中有4中元素可以作为根元素:Windows(窗口)、Page(网站页面)、Application(应用程序)、ResourceDictionary(逻辑资源集合)

XAML命名空间 习惯上带有x前缀 xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

其他命名空间

使用系统类

xmlns:s=”clr-namespace:System;assembly=mscorlib”

使用自定义类      自定义类必须有无参构造函数

1.使用本地自定义类

xmlns:local=”clr-namespace:Alex_WPFAPPDemo01″

示例:

public class Book
{
  public string Name { get; set; }
  public double Price { get; set; }

  public Book() { }

  public override string ToString()
  {
    return Name + “: ” + Price + “¥”;
  }
}

<Window x:Class=”Alex_WPFAPPDemo01.MainWindow”
     xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
     xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
     xmlns:local=”clr-namespace:Alex_WPFAPPDemo01″
     Title=”MainWindow” Height=”350″ Width=”525″>

  <Grid>
    <Button FontSize=”14″>
      <local:Book Name=”Self-learning WPF” Price=”30.0″ />
    </Button>
  </Grid>
</Window>

WPF学习之路(二) XAML

2.使用外部自定义类

xmlns:customlib=”clr-namespace:ThirdDll;assembly=ThirdDll”

To be continue…

下一篇: MongoDB Java Driver
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,146
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,618
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,461
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,236
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,871
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,953