Forum Cross Platform with Xamarin

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Data Binding Error

Hi, I wanted to use the data binding to add the products but then only errors will display saying 'Object Reference not set to an instance of an object".
Here are my codes:

ObservableCollection<InAppProduct> _products = new ObservableCollection<InAppProduct>();

public BuyProduct(GooglePurchase ggSearch=null)
        {
            _ggSearch = ggSearch;

            ProductView.ItemsSource = _products;

            _products.Add(new InAppProduct
            {
                SKU = "Small Monkey",
                Description = "Keyboard companion",
                Name = "monkey1.png"
            });
            _products.Add(new InAppProduct
            {
                SKU = "Small Monkey",
                Description = "Keyboard companion",
                Name = "monkey1.png"
            });
            _products.Add(new InAppProduct
            {
                SKU = "Small Monkey",
                Description = "Keyboard companion",
                Name = "monkey1.png"
            });

            InitializeComponent();

            NavigationPage.SetHasNavigationBar(this, false);

            var tapPurchase = new TapGestureRecognizer();
            var tapBackBtn = new TapGestureRecognizer();

            tapBackBtn.Tapped += OnTapBackBtnRecognizer;
            tapPurchase.Tapped += OnTapBuyProductRecognizer;
        }

xaml file:

<ListView x:Name="ProductView">
            <ListView.ItemTemplate>
              <DataTemplate>
                <TextCell Text="{Binding SKU}" />
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>

Best Answer

Answers

  • JenalynParagadosJenalynParagados USMember ✭✭

    Hi @PubuduGayan , Thanks. I just need to call this InitializeComponent(); before the implementation of the data binding

Sign In or Register to comment.