【发布时间】:2020-01-22 11:50:40
【问题描述】:
我似乎无法正确更新它,它只显示列表的前 2 项。
我正在从 Web API 接收 json 数据,我只是希望能够在列表视图中搜索名称并显示它,我已经尝试了很多这样的示例但似乎无法得到它要真正起作用,我是否需要将列表封装并订阅到 INotify?
<StackLayout>
<SearchBar TextChanged="SearchBar_TextChanged"></SearchBar>
<FlexLayout Wrap="Wrap" Direction="Row" JustifyContent="SpaceEvenly" >
<flv:FlowListView x:Name="productsListView"
FlowColumnCount="2" HasUnevenRows="false" RowHeight="320"
VerticalOptions="FillAndExpand"
SeparatorVisibility="None"
SelectedItem="{Binding Name}"
>
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Grid Padding="5">
<Frame BorderColor="#f39000" HeightRequest="310" >
<StackLayout Orientation="Vertical" Spacing="5">
<Label HorizontalTextAlignment="Center" FontSize="Medium" FontAttributes="Bold" TextColor="Black" x:Name="idlabel" Text="{Binding name}">
</Label>
<ffimageloading:CachedImage HorizontalOptions="Center" VerticalOptions="Center"
WidthRequest="150" HeightRequest="150"
DownsampleToViewSize="true"
Source = "{Binding description}">
</ffimageloading:CachedImage>
<Button Text="See Products"
Padding="5"
FontSize="Small"
BorderColor="#f39000"
BackgroundColor="#f39000"
CornerRadius="10"
TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Clicked="SupplierClicked"
BindingContext="{Binding id}"/>
</StackLayout>
</Frame>
</Grid>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
</FlexLayout>
</StackLayout>
public List<ProductTag> x;
public async Task InitAsync()
{
var p = await wc.Tag.GetAll(new Dictionary<string, string>() {
{ "per_page", "100" } });
x = p;
productsListView.FlowItemsSource = p;
}
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
//thats all you need to make a search
productsListView.BeginRefresh();
if (string.IsNullOrWhiteSpace(e.NewTextValue))
productsListView.ItemsSource = x;
else
productsListView.ItemsSource = x.Where(i => i.name.Contains(e.NewTextValue));
productsListView.EndRefresh();
}
【问题讨论】:
标签: c# json xamarin.forms