Clingingboy

<clingingboy:control runat="server"  />
Get Ready For WPF && SilverLight

博客园 首页 新随笔 联系 订阅 管理
  170 Posts :: 0 Stories :: 1296 Comments :: 362 Trackbacks
此示例基于 wpf学习笔记-指定数据源


1.让对象实现INotifyPropertyChanged接口,以便属性更改发出通知

    public class Person : INotifyPropertyChanged
    
{
        
public Person() { }
        
public Person(string name, int age)
        
{
            
this.name = name;
            
this.age = age;
        }


        
string name;
        
public string Name
        
{
            
get return this.name; }
            
set
            
{
                
this.name = value;
                OnPropertyChanged(
"Name");
            }

        }


        
int age;
        
public int Age
        
{
            
get return this.age; }
            
set
            
{
                
this.age = value;
                OnPropertyChanged(
"Age");
            }

        }



        
public event PropertyChangedEventHandler PropertyChanged;

        
protected void OnPropertyChanged(string propName)
        
{
            
if (this.PropertyChanged != null)
            
{
                PropertyChanged(
thisnew PropertyChangedEventArgs(propName));
            }

        }


    }

2.xaml(略去布局)


        
<Label Content="{Binding Name}"></Label>
        
<Label Content="{Binding Age}"></Label>
        
<TextBox Text="{Binding Path=Name, Source={StaticResource Tom}}" />
        
<TextBox Text="{Binding Age}" 
            
/>
这里又出现了新的绑定语法,{Binding Path=Age}等价{Binding Age}

3.目标:
当更改目标属性的时候,更新数据源(更新以后则绑定的对象也发生变化,如更改TextBox的Text则Label的Content也发生变化)

4.设置更新数据源执行时间
通过设置Binding对象的UpdateSourceTrigger  来确定执行时间.

根据需要设置UpdateSourceTrigger 属性

Tag标签: wpf,.net
posted on 2008-05-31 12:37 Clingingboy 阅读(121) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接: