2016-01-20 60 views
0

我有一個ObservableCollection正與在組合框這種方式創建用戶界面的綁定複選框更改屬性:WPF的ObservableCollection一次

<CheckBox IsChecked="{Binding Path=theItemIsSelected, Mode= TwoWay}" Margin="0,0,4,0" /> 

在這種情況下,「theItemIsSelected」是一個布爾值,只是一個標誌來指示該項目是否被選擇。當啓用/禁用另一個列表中的某些項目(我們稱之爲「主列表」)在主Listview上顯示/隱藏。

事實是,如果「」主列表「包含多個元素,則在逐個啓用標誌theItemIsSelected時,UI會更新得慢一些。

if (this.myObsCol != null) 
{ 
    for (int i = 0; i < this.myObsCol.Count; i++) 
    { 
     //This line allows to display the elements in the main list 
     this.myObsCol[i].theItemIsSelected = true; 
    } 
} 

有沒有清潔的方式在主列表中的元素顯示更快地做到這一點這樣:當用戶按下「全選」複選框,這段代碼被稱爲?

謝謝。

+0

試試這個:this.myObsCol.Select(OB => ob.theItemIsSelected = TRUE); – Jamaxack

回答

1

您可以使用並行LINQ對於這種情況:

if (this.myObsCol != null) 
{ 
    myObsCol.AsParallel() 
      .ForAll(x => x.theItemIsSelected = true); 
}