How to get the ListBoxItem for an item in ListBox on “bind-time”

喜你入骨 提交于 2019-12-02 01:19:20

Actually a better solution seems to be using the ItemContainerGenerator. Hook up an event handler on creation:

ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;

And make the event handler do what needs to be done:

protected void ItemContainerGenerator_StatusChanged(object sender, System.EventArgs e)
{
    if (ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
        EvaluateInitialElements(); 
}

The event OnRender is triggered when the component is ready to be rendered, and hence the ListBoxItem's are created. Doing the initial handling of the filtering on this event seems to ensure that everything I need is ready. I evaluate and disable elements, and then trigger the rendering:

protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
{
    EvaluateInitialElements();
    base.OnRender(drawingContext);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!