Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > XAML 学习(1)
【标  题】:XAML 学习(1)
【关键字】:XAML
【来  源】:http://blog.csdn.net/jk007/archive/2006/10/24/1349053.aspx

XAML 学习(1)

Your Ad Here

1.普通的写法

<Canvas>
      <TextBox Name="txtShow" Text="Hello" />
      <TextBlock Canvas.Top="25">
        <TextBlock.Text>
          <Binding ElementName="txtShow" Path="Text" />
        </TextBlock.Text>
      </TextBlock>
   </Canvas> 

2.简化的写法.

<Canvas>
        <TextBox Name="txtShow" Text="Hello" />
        <TextBlock Canvas.Top="25"
           Text="{Binding ElementName=txtShow, Path=Text}" />
      </Canvas> 

ElementName 属性(它用于绑定到一个控件),而不是使用 Source 属性。

3.NET 对象绑定:
<Window x:Class="WindowsApp2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:BindNonTextProperty"
    Title="WindowsApp2" Height="300" Width="300"
    >
    <Grid>
      <Grid.Resources>
        <c:MyData x:Key="MyDataSource"/>
      </Grid.Resources>
     
      <Grid.DataContext>
        <Binding Source="{StaticResource MyDataSource}"/>
      </Grid.DataContext>
      <Button Background="{Binding Path=ColorName}" Width="150" Height="30">I am bound to Green!</Button>
      <Button Background="{Binding Source={StaticResource MyDataSource},Path=ColorNameT}" Width="20" Height="60">Red!</Button>
     
    </Grid>
</Window>

类文件

using System;

namespace BindNonTextProperty
{
    public partial class MyData
    {
        private string _data = "Green";

        public string ColorName
        {
            get
            {
                return _data;
            }
        }

        public string ColorNameT
        {
            get
            {
                return "Red";
            }
        }
    }
}

 

Borland传奇拾遗:BDS 2006/Delphi 2006:【上一篇】
用Visual Studio 2005进行程序开发:【下一篇】
【相关文章】
  • 在XAML之中通过Mapping URI使用自定义元素的步骤
  • [WinFX]WinFX 12月份CTP发布,其中包含了XAML设计器
  • MyXaml
  • Hello, XAML World
  • 【随机文章】
  • Servlets/JSP开发技术问答
  • sql server防黑所需执行脚本
  • Weblogic中使用Servlet
  • mysql学习笔记
  • 复习J2SE连接SQL Server数据库小有收获
  • 非阻塞套接字(Nonblocking Sockets) 概述
  • Enable Mac OS X 'root' User
  • 我的收藏哈哈
  • RadialGradientBrush's Coolness
  • 软件文档知多少?
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.