我的ItemControl通過ItemsSource綁定到ObservableCollection < ...>。當我填充集合時,程序需要一些時間來創建正確的ItemTemplate對象並將它們呈現在我的ItemsControl中。如果我的ItemsControl已經結束創建(渲染,顯示)通過ItemsSource綁定的集合,是否有任何方法可以知道? 請幫忙。我真的需要這個答案。在填充ObservableCollection之後,我想處理這個集合的對象。不幸的是,一些信息正在丟失,因爲ItemsControl仍在創建它的項目(ItemTemplates)。等待itemcontrol呈現
* 編輯 爲了更好地理解: 的ObservableCollection < ...> MyCollection的被綁定到MyItemsControl的的ItemsSource。
我運行代碼:
for(int i = 0; i < ...; i++)
{
MyCollection.Add(MyItem);
}
// await Task.Delay(100) // If this line is not commented, everything works fine...
// ..but I don't think it's a good idea to solve that problem in this way.
foreach(Object o in MyCollection)
{
// The line under, is faster that the ItemsControl rendering...
// ...so the Work is not displayed.
o.DoSomeWorkThatShouldBeDisplayedInItemTemplateOfMyItemsControl
}
* EDIT 2 解決:LayoutUpdated事件
它是什麼具體說明DoSomeWorkThatShouldBeDisplayedInItemTemplateOfMyItemsControl'在做什麼? –
更改MyItem的狀態,Enum屬性。這應該會導致ItemTemplate的VisualState發生更改。 – jozefkarton