小编Jos*_*oso的帖子

Xamarin表单ListView不从ObservableCollection更新

我的XAML文件的ListView正在填充一个ViewModel,它具有来自服务的ObservableCollection,但ListView没有显示信息.我已经检查该服务是否返回了正确的信息.

这是我的XML文件的代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XAMLUnit1.Views.NetflixRoulettePage" Title="Movie">
    <ContentPage.Content>
         <StackLayout>
         <AbsoluteLayout>
                <BoxView Color="Gray"  AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"></BoxView>
                <SearchBar x:Name="searchBar"
                           Placeholder="Search By Actor's name" 
                           PlaceholderColor="White"
                           AbsoluteLayout.LayoutFlags="All"
                           AbsoluteLayout.LayoutBounds="0.1,0.1,1,1"  SearchCommand="{Binding SearchMovieCommand}" ></SearchBar>
            </AbsoluteLayout>

       <ListView  x:Name="ListOfMovies"  
            ItemsSource="{ Binding MovieList}" >
            <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout>
                                <ImageCell 
                                        ImageSource="{Binding poster_path, StringFormat='https://image.tmdb.org/t/p/w500{0}'}">
                                </ImageCell>
                                    <StackLayout Orientation="Horizontal">
                                    <TextCell Detail="{Binding title}"></TextCell>
                                    <TextCell Detail="{Binding release_date}"></TextCell>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

这是调用服务的ViewModel,它使用ObservableCollection作为ListView的ItemsSource:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms; …
Run Code Online (Sandbox Code Playgroud)

c# cross-platform observablecollection xamarin xamarin.forms

0
推荐指数
1
解决办法
3101
查看次数