Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Issue with data binding from a label

$
0
0

I have a label that is set to bind to my sqlite database but each time I submit an item to the database, the label comes in as null

Here is my Main.cs
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using MarketScanner.Models;

using Xamarin.Forms;
using System.ComponentModel;

namespace MarketScanner
{
public class Main : ContentPage , INotifyPropertyChanged
{
public string time;

    public Main()
    {


        returnDate();
        this.BindingContext = new custScanned();
        var entCustomerNumber = new Entry()
        {
            Placeholder = "Dealer Number",
            BackgroundColor = Color.White,
            TextColor = Color.Black,
            Keyboard = Keyboard.Telephone,

        };            
        entCustomerNumber.SetBinding(Entry.TextProperty, "custNumber");

        var current = new Label()
        {
            Text = "Current",
            TextColor = Color.White,
            BackgroundColor = Color.Red,
        };
        current.SetBinding(Label.TextProperty, "scannedDate");

        var btnEnterNumber = new Button()
        {
            Text = "Enter Dealer"
        };

        btnEnterNumber.Clicked += (sender, e) =>
         {                 
             current.Text = time.ToString();
             var cn1 = (custScanned)BindingContext;
             App.Database.SaveItem(cn1);
         };

        var btnSync = new Button()
        {
            Text = "Send Data"
        };

        Content = new StackLayout
        {
            BackgroundColor = Color.Black,
            Children = {
                entCustomerNumber,
                btnEnterNumber,                                      
                btnSync,
                current,
            }
        };


    }



           public string returnDate()
           {

               try
               {
                   DateTime dt = DateTime.Now;
                   time = dt.ToString();
               }
               catch (Exception ex)
               {

               }

              // var currentTime = (string.Format("{0}", now));
               return time;
           }


}

}
`


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>