等待itemscontrol渲染

时间:2012-11-18 23:09:52

标签: wpf data-binding itemscontrol itemrenderer itemtemplate

我的ItemControl通过ItemsSource绑定到ObservableCollection< ...>。当我填充集合时,程序需要一些(一点点,但仍然有一些)时间来创建正确的ItemTemplate对象并在我的ItemsControl中渲染它们。如果我的ItemsControl已经结束创建(渲染,显示)通过ItemsSource绑定的集合,有没有办法知道? 请帮忙。我真的需要这个答案。在填充ObservableCollection之后,我想处理这个集合的对象。不幸的是,有些信息丢失了,因为ItemsControl仍在创建它的项目(ItemTemplates)。

*的修改 为了更好地理解: 的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
}

* 编辑2 已解决:LayoutUpdated事件

2 个答案:

答案 0 :(得分:0)

我明白了。 LayoutUpdated事件是我需要的。在另一个论坛上找到,但希望将来有所帮助。

答案 1 :(得分:-1)

尝试System.Windows.Forms.Application.DoEvents();