简体   繁体   English

Xamarin在ListView中形成条件格式

[英]Xamarin Forms conditional formatting within a ListView

In the code-behind of the parent page, how do we say, 在父页面的代码背后,我们怎么说:

foreach(label in the ListView)
{
   if(label.Text == "something")
   {
        //do some formatting
   }
}

I think this should be in the override of OnAppearing but I'm not sure of the syntax. 我认为这应该在OnAppearing的替代中,但是我不确定语法。

thanks 谢谢

UPDATE: In response to comments, the ListView has 2 labels, I want to say, if label1 = "x", do specific formatting on label2. 更新:为了回应评论,ListView有2个标签,我想说,如果label1 =“ x”,请对label2进行特定的格式化。

Hope that's a bit clearer 希望这更清楚

There is a property in ListView named TemplatedItems that return a ViewCell and we can get from this ViewCell all views that we have (if you use template may it will be a little bit different). ListView有一个名为TemplatedItems的属性,该属性返回一个ViewCell ,我们可以从该ViewCell中获得我们拥有的所有视图(如果使用template,则可能会有些不同)。

    foreach (ViewCell myViewCell in mylist.TemplatedItems)
    {

        Label myLabel = (Label) myViewCell.View;
        if (myLabel.Text == "smth")
        {
            //do some formatting

        }
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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