仅针对xamarin中的特定列表项在listview中隐藏行
我的xaml中有一个分组列表视图 以下是listView对象: 附件:仅针对xamarin中的特定列表项在listview中隐藏行,listview,xamarin,mvvm,xamarin.forms,Listview,Xamarin,Mvvm,Xamarin.forms,我的xaml中有一个分组列表视图 以下是listView对象: 附件: public string TCPNumber { get; set; } public string AttachmentName { get; set; } public int FileType { get; set; } 这些组的名称是基于文件类型值的X和Y。 每个列表项显示上述3项的值。 我想在文件类型值为2的组Y列表项中隐藏TCPNumber项 下面是我的xaml: <ContentPage.Resour
public string TCPNumber { get; set; }
public string AttachmentName { get; set; }
public int FileType { get; set; }
这些组的名称是基于文件类型值的X和Y。
每个列表项显示上述3项的值。
我想在文件类型值为2的组Y列表项中隐藏TCPNumber项
下面是我的xaml:
<ContentPage.Resources>
<ResourceDictionary>
<converter:TCPGridVisibleConverter x:Key="TCPGridVisible" />
</ResourceDictionary>
<ContentPage.Resources>
<ListView x:Name="lvTCPs" HasUnevenRows="True"
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding Key}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Path=FileType, Source={x:Reference
Name=AttachmentsTabPage}, Converter={StaticResource TCPGridVisible}}">
</RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
</ListView>
我编写了一个关于在文件类型值为2的组Y列表项中隐藏TCPNumber项的演示
首先,我在listview项的不同行中设置了TCPNumber
,AttachmentName
,FileType
。当filetype值为2时,第一行的TCPNumber
将隐藏,如下面的屏幕截图所示
这是我的xaml
<StackLayout>
<ListView x:Name="lvTCPs" HasUnevenRows="True" >
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="KEY"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding FileType, Converter={local:TCPGridVisibleConverter} }"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="{Binding TCPNumber}" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding AttachmentName}" Grid.Row="1" Grid.Column="0" />
<Label Text="{Binding FileType}" Grid.Row="2" Grid.Column="0" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
这是我的数据
List<TCP> list = new List<TCP>();
list.Add(new TCP("1001","abc",2));
list.Add(new TCP("1002", "bca", 1));
list.Add(new TCP("1003", "bca", 2));
list.Add(new TCP("1004", "abc", 1));
list.Add(new TCP("1005", "abc", 1));
lvTCPs.ItemsSource = list;
希望它能对您有所帮助。我编写了一个演示,介绍如何在文件类型值为2的Y组列表项中隐藏TCPNumber项
首先,我在listview项的不同行中设置了TCPNumber
,AttachmentName
,FileType
。当filetype值为2时,第一行的TCPNumber
将隐藏,如下面的屏幕截图所示
这是我的xaml
<StackLayout>
<ListView x:Name="lvTCPs" HasUnevenRows="True" >
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="KEY"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding FileType, Converter={local:TCPGridVisibleConverter} }"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="{Binding TCPNumber}" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding AttachmentName}" Grid.Row="1" Grid.Column="0" />
<Label Text="{Binding FileType}" Grid.Row="2" Grid.Column="0" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
这是我的数据
List<TCP> list = new List<TCP>();
list.Add(new TCP("1001","abc",2));
list.Add(new TCP("1002", "bca", 1));
list.Add(new TCP("1003", "bca", 2));
list.Add(new TCP("1004", "abc", 1));
list.Add(new TCP("1005", "abc", 1));
lvTCPs.ItemsSource = list;
希望它能对您有所帮助。如果您想隐藏整行,我认为首先不将其包含在ItemsSource中会更容易。我只想在listitem的文件类型值为2时隐藏该行,否则我需要填充该行,那么为什么不在构建ItemsSource时过滤掉FileType=2?实际上,我的要求是不删除列表项。我想删除/隐藏文件类型值为2的每个列表项的第一行。如何使用ItemSource进行筛选?您确实需要编辑您的问题,以澄清您指的是ViewCell网格的行,不是ListView的行如果您想隐藏整行,我认为首先不将其包含在ItemsSource中会更容易我只想在listitem的FileType值为2时隐藏该行,否则我需要填充该行,那么为什么不在构建ItemsSource时过滤掉FileType=2?实际上我的要求不是正在删除列表项。我想删除/隐藏文件类型值为2的每个列表项的第一行。如何使用ItemSource进行筛选您确实需要编辑您的问题,以澄清您指的是ViewCell网格的行,而不是ListViewYes的行。是的,这很有帮助。谢谢。是的,它很有帮助。非常感谢。