簡體   English   中英

如何在Windows Phone 8.1中訪問ListView DataTemplate中的控件

[英]how to access controls in listview datatemplate in windows phone 8.1

我需要在列表視圖數據模板中訪問網格,但是當使用此代碼時,程序到達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;
                }
            }
        }
    }
}

這段代碼Active_list.Items不會給您任何控制權,而是您的實際數據。 如果要訪問列表視圖中的特定控件,則需要遍歷可視化樹並手動找到它。 我認為手動更改列表視圖中的控件不是一個好習慣。

但是,如果您真的想這樣做,我建議您以類似的問題查看該主題: 如何使用DataTemplate訪問列表框中的特定項目?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM