【问题标题】:how to access controls in listview datatemplate in windows phone 8.1如何在 Windows Phone 8.1 中访问列表视图数据模板中的控件
【发布时间】:2015-03-17 10:30:57
【问题描述】:

我需要访问列表视图数据模板中的网格,但是当使用此代码时,程序会到达 foreach 循环并且不执行它

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;
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# windows-phone-8.1


    【解决方案1】:

    这个代码Active_list.Items 不会给你任何控制,但你的实际数据。如果要访问列表视图中的特定控件,则需要遍历可视化树并手动找到它。我认为手动更改列表视图中的控件不是一个好习惯...

    但如果你真的想这样做,我建议你用类似的问题查看这个主题:How to access a specific item in a Listbox with DataTemplate?

    【讨论】:

    • 在这个问题中,他在单击列表框时访问控件,但我需要在我的列表视图中获取所有控件。
    • 我现在无法检查,但我想这些控件应该在Active_list.Children 中。在foreach 循环之前设置断点时,您可以查看那里有哪些控件。
    • Active_list.Children 不工作,你可以检查告诉我
    • 当您设置断点并在调试模式下运行您的应用程序时,应用程序将在断点处停止。然后您可以在代码中将鼠标光标指向Active_list,VisualStudio 将向您显示它的属性。然后你将它们展开并浏览以查看里面的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多