如何保持列表框属性更新? [英] How to keep a listbox property updated?

查看:66
本文介绍了如何保持列表框属性更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个列表框(Windows Phone 7),并且将Item源设置为Sample类型的项目列表:

Lets say I have a listbox (Windows Phone 7) and I set the Item source to a list of items of type Sample:

public class Sample
{
    public string sampleOne {get;set;}
    public string samplewo {get;set;}
}



现在在xaml中,我有一个带有两个文本框的DataTemplate,其值绑定到数据类型属性(sampleOne,sampleTwo).
我想做的是,如果我更改一项的属性,如下所示:



Now in the xaml I have a DataTemplate with two text boxes which values are binded to the data type propertie (sampleOne, sampleTwo).

What Im trying to do is that if I change the property of one item like this:

((Sample)listBox.Items[0]).sampleOne = "test";





It would be also updated in the Xaml (text box) to the user.

推荐答案

有几种方法可以做到这一点,但这是一个选择:
http://msdn.microsoft.com/zh-我们/library/system.windows.dependencyproperty%28v=vs.95%29.aspx [ http://www.silverlightshow.net/items/Tip-How-to-de-clare-a-dependency-property-in-Silverlight.aspx [ http://msdn.microsoft.com/en-us/library/system.componentmodel. inotifypropertychanged.aspx [^ ]
http://msdn.microsoft.com/zh-我们/library/system.componentmodel.inotifypropertychanged%28v=vs.95%29.aspx [
there are several ways of doing this, but this is one option:
http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty%28v=vs.95%29.aspx[^]
http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx[^]

Thr other one os to use an observable collection that implements INotifychange on the individual items:
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx[^]
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged%28v=vs.95%29.aspx[^]


这篇关于如何保持列表框属性更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆