Listview Xamarin Forms ListVew Binding-将ViewCell标签绑定到方法

Listview Xamarin Forms ListVew Binding-将ViewCell标签绑定到方法,listview,xamarin.forms,binding,Listview,Xamarin.forms,Binding,我使用的是使用MVVM方法的Xamarin表单,效果很好 我需要向现有ListView添加功能,以便在绑定值为某个值时显示文本 这是生成描述的单元格 <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout> <Label Text="{Binding Des

我使用的是使用MVVM方法的Xamarin表单,效果很好

我需要向现有ListView添加功能,以便在绑定值为某个值时显示文本

这是生成描述的单元格

   <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <Label Text="{Binding Description}"  x:Name="lblDescription" 
               Style="{DynamicResource ListItemTextStyle}" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
id要将visible绑定到方法,如:

Visible="{Binding IsDescriptionOk}"

但是在列表视图中,如果有意义的话,我需要传入项索引?

我想可能有多种方法可以解决这类问题。其中之一可能是使用。大概是这样的:

<ViewCell>
    <StackLayout>
        <Label
            Text="{Binding Description}"
            Style="{DynamicResource ListItemTextStyle}"
            IsVisible="{Binding Description, Converter="{StaticResource ItemStatusToVisiblityConverter}" />
    </StackLayout>
</ViewCell>


为什么需要通过索引?为什么不能根据Description属性的长度返回bool呢?这只是一个例子,我想查找实际的描述,例如:如果描述是“在线”,那么返回false,如果描述是“正在进行”,那么返回true等等……感谢您的回复-我有没有办法调用函数?因为我所做的只是比较另一个对象中的条目列表,所以您可以将此“函数”移动到IValueConverter,并将“另一个对象”作为参数传递给IValueConverter。但是,再一次,为什么不在将列表分配给列表之前对其进行筛选呢?听起来这对你的情况更有意义。谢谢你迄今为止的帮助,你有没有关于IValueConverter在这种情况下会是什么样子的示例?。在一个简单的形式,所以我可以建立在它。上面的示例有点复杂,让我开始学习。谢谢,但我仍然不确定如何从xaml绑定运行ypur示例中的IsdescriptionOk函数。示例代码:
Visible=“{Binding IsdescriptionOk}”
<ViewCell>
    <StackLayout>
        <Label
            Text="{Binding Description}"
            Style="{DynamicResource ListItemTextStyle}"
            IsVisible="{Binding Description, Converter="{StaticResource ItemStatusToVisiblityConverter}" />
    </StackLayout>
</ViewCell>
private string _description = null;

public string Description {
  get {
    if (_description == null) {
      // method to fetch/build description 
      _description = GetDescription();
    }
    return _description;
  }

public bool IsDescriptionOK {
  get {
    if ((Description == "Online") || (other values here...)) return false;
    return true;
  }
}