I am trying to filter data from firebase in my xamarin forms app.
Here is code of my list view in .xaml page
<ListView x:Name="listView" ItemsSource="{Binding ProductList}" HasUnevenRows="true" SeparatorVisibility="None" BackgroundColor="#fafafa">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="0,0,0,40">
<Label Text="{Binding Name}" FontSize="Large" TextColor="Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In cs file of xaml page i have inside constructor:
BindingContext = new ProductsViewModel(userId, Navigation, productType);
And this is my ViewModel
public class ProductsViewModel : BaseViewModel
{
public Guid UserId { get; set; }
public string ProductType { get; set; }
private APIService services;
public INavigation Navigation { get; }
private ObservableCollection<ProductModel> _ProductList = new ObservableCollection<ProductModel>();
public ObservableCollection<ProductModel> ProductList
{
get { return _ProductList; }
set
{
_ProductList = value;
OnPropertyChanged();
}
}
public ProductsViewModel(Guid userId, INavigation navigation, string productTyp)
{
UserId = userId;
ProductType = productTyp;
services = new APIService();
Navigation = navigation;
ProductList = services.GetProducts();
}
}
And my APIService's class
internal ObservableCollection<ProductModel> GetProducts()
{
var outfitFeedData = firebase
.Child("Products")
.AsObservable<ProductModel>()
.AsObservableCollection();
return outfitFeedData;
}
All works fine until i start to query result, then i start getting convert type exceptions.
EG:
internal ObservableCollection<ProductModel> GetProducts()
{
var outfitFeedData = firebase
.Child("Products")
.AsObservable<ProductModel>()
.AsObservableCollection().Select(item => new ProductModel
{
Type = "K",
});
return outfitFeedData;
}
question from:
https://stackoverflow.com/questions/65873849/query-data-from-firebase-xamarin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…