六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 262|回复: 0

WPF之数据绑定基础

[复制链接]

升级  60%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
30
 楼主| 发表于 2013-1-3 15:38:22 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">    关于WPF的数据绑定,本人愚见,将其分为两大类。一类为绑定到界面元素的属性,多用于一些界面设计中,以本人目前的眼界来看,此类需求相对较少;另一类则为用户数据的绑定,多用于数据展示。
    下面就几个简单的小例子,阐述下这两种绑定的一些基本做法。
    一、绑定到界面元素
    绑定到界面元素,相对比较容易,这里用一个简单的例子简要说明下基本的语法。   
<div class="cnblogs_code"><Window x:Class="BindPracitce.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="350" Width="525">    <Grid>        <StackPanel>            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"                        Background="Gray" Foreground="White"  Width="100" Height="30"                        x:Name="OriginalText" Text="{Binding ElementName=OriginalText2,Path=Text,Mode=OneWay}" />            <TextBox  VerticalAlignment="Center" HorizontalAlignment="Center" Width="100"                       Text="{Binding ElementName=OriginalText,Path=Text,Mode=OneWayToSource,UpdateSourceTrigger=LostFocus}"/>            <TextBox Width="100" x:Name="OriginalText2"/>        </StackPanel>    </Grid></Window>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表