2010-10-27 47 views
0

請我需要幫助:的Silverlight:需要幫助的IEnumerable

我有一個列表框綁定到IEnumerable的源

人是包含下列屬性的類:名稱(字符串),器isChecked(布爾)

我需要更改名爲「Bob」的特定人員的房產「isChecked」

我無法更改該房產的價值!

請幫助

+0

您目前有哪些代碼? – ChrisF 2010-10-27 12:37:31

回答

1

如果你想有,當你更新你的模型顯示的值進行更新,那麼你可能需要實現你的模型類,例如INotifyPropertyChanged的

public class Person : INotifyPropertyChanged 
{ 
    public string Name 
    { 
     get 
     { 
      return this.name; 
     } 
     set 
     { 
      this.name = value; 
      this.FirePropertyChanged("Name"); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    protected void FirePropertyChanged(string propertyName) 
    { 
     if (this.PropertyChanged != null) 
     { 
      this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 
0

我假設你只需要一次改變它的看法?

根據您擁有的數據量,最簡單的實現方法是將模型中的數據擴展爲例如一個List<>,然後進行修改並將您的控件綁定到該列表。

var people = myDataSource.ToList(); // a LINQ extension - you may need a 'using' 
var bob = people.FirstOrDefault(p => p.Name == "Bob"); 
if (bob != null) 
{ 
    bob.isChecked = true; 
} 

或者,也許更好的是,使用例如動畫進行改變。 a Select()

var peopleWithBobTicked = myDataSource.Select(
    p => { 
      if (p.Name == "BoB") p.isTicked = true; 
      return p; 
     });