How get visual items of a ComboBox using databinding?

杨岑 121 Reputation points
2024-04-17T12:48:02.6533333+00:00

It's a followup question of https://learn.microsoft.com/en-us/answers/questions/1656636/how-do-i-know-when-a-binding-is-complete.

The ComboBox is databound using ItemsSource, now I don't have control of the Items property because it's a simply set to what ItemsSource is.

I need to enumerate over the generated visual items, how do I get them?

I tried the following code, but did not get what I expected.

var root = VisualTreeHelper.GetChild(combo1, 0);
var cc = VisualTreeHelper.GetChildrenCount(root);
for (int i = 0; i < cc; i++)
{
    var child = VisualTreeHelper.GetChild(root, i);
    if (child is FrameworkElement elem)
        Debug.WriteLine(elem.Name);
}
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. 杨岑 121 Reputation points
    2024-04-18T12:43:31.8233333+00:00

    Oh my... At last, I found the answer myself.

    for (var i = 0; i < myListView.Items.Count; i++)
    {
        var lvi = (ListVieItem)myListView.ContainerFromIndex(i);
    }
    

    But I am still stuck at this problem: https://learn.microsoft.com/en-us/answers/questions/1656636/how-do-i-know-when-a-binding-is-complete.

    0 comments No comments