C# 在xamarin表单列表视图中查找和删除元素

C# 在xamarin表单列表视图中查找和删除元素,c#,xamarin.forms,C#,Xamarin.forms,我有xamarin.forms.listview控件,其中有一些元素。此listview将动态填充。现在有一个特别的问题 条件,我需要在listview中隐藏一个元素,如何 找到并隐藏它 <ListView x:Name="lstBids" Margin="0" HasUnevenRows="True"> <ListView.ItemTemplate > <DataTemplate> <ViewCell&g

我有xamarin.forms.listview控件,其中有一些元素。此listview将动态填充。现在有一个特别的问题 条件,我需要在listview中隐藏一个元素,如何 找到并隐藏它

<ListView x:Name="lstBids" Margin="0" HasUnevenRows="True">
    <ListView.ItemTemplate >
        <DataTemplate>
            <ViewCell>
                <Frame Margin="0,0,0,5" Padding="0" BackgroundColor="White">
                    <StackLayout Orientation="Vertical">
                        <Label Style="{StaticResource Medium}" Margin="10" HorizontalOptions="StartAndExpand" x:Name="lblComments" Text="{Binding Comments}"></Label>
                                <Frame x:Name="frmHire" BackgroundColor="{StaticResource base}" Padding="10,5" CornerRadius="5" HasShadow="False">
                                    <Label Text="Hire" Style="{StaticResource MediumWhite}"></Label>
                                    <Frame.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="Hire_Clicked"></TapGestureRecognizer>
                                    </Frame.GestureRecognizers>
                                </Frame>
                            <Label Style="{StaticResource SmallGray}" HorizontalOptions="EndAndExpand"  Margin="0,0,10,0"  x:Name="lblDate" Text="{Binding UpdatedDate, StringFormat='{0:MMMM dd, yyyy hh:mm tt}'}"></Label>
                    </StackLayout>
                </Frame>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


frmHire
是我需要在特定条件下隐藏在所有listview项中的帧,我如何实现它?请帮助我。

只需将
frmHire
上的
IsVisible
属性绑定到
itemsource
项上的条件即可


承载
ObservableCollection
列表的父视图模型只需遍历项目并相应地设置条件即可。

您不需要设置帧的名称并将其放入代码隐藏中。正如Roubachof所说,您可以使用数据绑定来绑定
IsVisible
的值,并在ViewModel中对其进行更改

在xaml中

您可以设置它的值。例如,如果要将所有帧
isVisible
设置为
false

foreach(var model in MyItems)
{
  model.IsVisible = false;
}
MyItems是listview的
ItemsSource
。在初始化ItemsSource时,不要忘记初始化属性。否则,
的值在默认情况下可见
false

public class Model : INotifyPropertyChanged
{
  public string Comments { get; set; }

  public event PropertyChangedEventHandler PropertyChanged;



  protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
  {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  }

  private bool isvisible;
  public bool IsVisible
  {
    get
    {
       return isvisible;
    }
    set
    {
      if (isvisible != value)
      {
         isvisible = value;
         NotifyPropertyChanged();
      }
     }
 }

        //...other property
}
foreach(var model in MyItems)
{
  model.IsVisible = false;
}