0

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;
                }
            }
        }
    }
}
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
ahmad
  • 55
  • 5

1 Answers1

0

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?

Community
  • 1
  • 1
Łukasz Rejman
  • 1,892
  • 1
  • 11
  • 18
  • in this question he access the control when the listbox is clicked, but i need to get all the controls in my listview. – ahmad Mar 18 '15 at 07:32
  • I can't check it now, but I guess these controls should be in `Active_list.Children`. When you set a breakpoint just before the `foreach` loop, you can look what controls are there. – Łukasz Rejman Mar 18 '15 at 07:59
  • Active_list.Children not working when you can check it tell me – ahmad Mar 18 '15 at 09:30
  • When you set a breakpoint and run your app in debug mode, then the app will stop on the breakpoint. Then you can point mouse cursor on `Active_list` in code and VisualStudio will show you properties of it. Then you den expand them and browse to see what's inside. – Łukasz Rejman Mar 18 '15 at 09:38