2017-05-28 14 views
0

データをバインドしようとしましたが、リストビューに何も表示されずデバッグしましたが、アイテムが正しく表示されていますがリストビューには何も表示されません。私は多くのことを、検索ビューを一覧表示するには私のリストをバインドすることができますが、私はすべてのソリューションにXamarinフォームListViewのグリッドのコンポーネントにデータをバインドする

ResultPage.xaml.cs

using System; 
using System.Collections.Generic; 
using FindDiscount.Models; 
using Xamarin.Forms; 
using System.Collections.ObjectModel; 

namespace FindDiscount { 
    public partial class ResultPage : ContentPage { 
     public ObservableCollection<resultModel> products; 

     public ResultPage(int distance, string productName) { 
      InitializeComponent(); 
      initData(); 



     } 


     public ResultPage() { 
      InitializeComponent(); 

     } 

     void initData(){ 

      products = new ObservableCollection<resultModel>(); 
      products.Add(new resultModel{ 
       productName="Samsung Note 4", 
       companyName="Samsung", 
       productPrice=1000, 
       discountRate=15, 
       imageURL="hamburger.png" 
      }); 
      products.Add(new resultModel { 
       productName = "iphone 7", 
       companyName = "Apple", 
       productPrice = 3000, 
       discountRate = 45, 
       imageURL = "hamburger.png" 
      }); 
      products.Add(new resultModel { 
       productName = "Windows Phone ", 
       companyName = "Microsoft", 
       productPrice = 1000, 
       discountRate = 15, 
       imageURL = "hamburger.png" 
      }); 
      ProductsListView.ItemsSource = products; 
     } 
    } 
} 

を見つけるために管理していませんでしたどのようにResultPage.xaml

<?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="FindDiscount.ResultPage"> 
    <ContentPage.Content> 

    <ListView x:Name="ProductsListView" HasUnevenRows="true" ItemsSource="{Binding products}"> 
     <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell> 
       <ViewCell.View> 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="*"/> 
           <RowDefinition Height="*"/> 
           <RowDefinition Height="*"/> 
           <RowDefinition Height="*"/> 
          </Grid.RowDefinitions> 

          <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="*"/> 
           <ColumnDefinition Width="*"/> 
          </Grid.ColumnDefinitions> 

          <Image Grid.Row="0" Grid.Column="0" Source="{Binding imageURL}" />  

          <Label Grid.Row="0" Grid.Column="1" Text="{Binding productName}" TextColor="Black" /> 

          <Label Grid.Row="1" Grid.Column="1" Text="{Binding companyName}" TextColor="Black" /> 

          <Label Grid.Row="2" Grid.Column="0" Text="{Binding productPrice}" TextColor="Black" /> 

          <Label Grid.Row="2" Grid.Column="1" Text="{Binding discountRate}" TextColor="Black" /> 

          <Button Grid.Row="3" Grid.Column="1" Text="Locaiton" TextColor="Black" /> 

         </Grid> 
        </ViewCell.View> 
       </ViewCell>    
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 


    </ContentPage.Content> 
</ContentPage> 
+0

私は同じコードでMVVMを使用して私の問題を解決しました –

答えて

0

私は思いますあなたは

public ObservableCollection<resultModel> products {get; set;} 

のようなものを書いて、あなたでINotifyPropertyChangedを実装する必要があります

関連する問題