简体   繁体   中英

how to access controls in listview datatemplate in windows phone 8.1

I need to access a grid in a list-view data-template, but when using this code the program reaches the foreach loop and don't execute it

foreach (Grid firstgrid in Active_list.Items)
{
    var item = Active_list.ItemContainerGenerator.ContainerFromItem(firstgrid);
    var ch = AllChildren(item);
    var tag = url;
    var control = (Grid)ch.First(c => c.Tag == tag);
    if (firstgrid.GetType() == typeof(Grid))
    {
        if ((String)firstgrid.Tag == url)
        {
            foreach (ProgressBar prg in firstgrid.Children)
            {
                if (prg.GetType() == typeof(ProgressBar))
                {
                    prg.IsIndeterminate = false;
                }
            }
            foreach (TextBlock txt in firstgrid.Children)
            {
                if (txt.GetType() == typeof(TextBlock))
                {
                    txt.Visibility = Visibility.Visible;
                }
            }
        }
    }
}

This code Active_list.Items won't give you any control but your actual data. If you want to access specific control in you list view, you need to go through your visual tree and find it manually. I think it's not a good practice to manually change controls inside list view...

But if you really want to do it this way I recommend you to check out this topic with similar question: How to access a specific item in a Listbox with DataTemplate?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM