I can not implement an SfDataGrid

0

Trying to follow a tutorial here to create a SfDataGrid, but it is not working. I'm full of doubts on how to implement. My Model Class

namespace Autorizador.Model
    {
        public class LiberacaoGrid
        {
            private double dataLib;
            private string cliente;
            private string vendedor;
            private string filial;

            public double DataLib
            {
                get { return dataLib; }
                set { this.dataLib = value; }
            }
            public string Cliente
            {
                get { return cliente; }
                set { this.cliente = value; }
            }
            public string Vendedor
            {
                get { return vendedor; }
                set { this.vendedor = value; }
            }
            public string Filial
            {
                get { return filial; }
                set { this.filial = value; }
            }
            public LiberacaoGrid(double datalib, string cliente, string vendedor, string filial)
            {
                this.DataLib = datalib;
                this.Cliente = cliente;
                this.Vendedor = vendedor;
                this.Filial = filial;
            }
        }

Another class called a repository

namespace Autorizador.Model
{
    public class LiberacaoRepository
    {
        DataService dataService;
        List<Liberacao> lib;
        private ObservableCollection<LiberacaoGrid> orderInfo;
        public ObservableCollection<LiberacaoGrid> OrderInfoCollection
        {
            get { return orderInfo; }
            set { this.orderInfo = value; }
        }
        public LiberacaoRepository()
        {
            dataService = new DataService();
            orderInfo = new ObservableCollection<LiberacaoGrid>();
            this.AtualizaDados();
        }
        public async void AtualizaDados()
        {
            lib = await dataService.GetLiberaAsync();
        }

    }

My App.xaml.cs

namespace Autorizador
{
    public partial class App : Application
    {
        SfDataGrid dataGrid;
        public App()
        {
            InitializeComponent();

            dataGrid = new SfDataGrid();
            MainPage = new ContentPage { Content = dataGrid };
        //MainPage = new Autorizador.MainPage();
        //MainPage = new NavigationPage(new Autorizador.MainPage());
    }


    protected override void OnStart()
    {
        //CrossPushNotification.Current.Unregister();
        //CrossPushNotification.Current.Register();
    }

    protected override void OnSleep()
    {
        // Handle when your app sleeps
    }

    protected override void OnResume()
    {
        // Handle when your app resumes
    }
}

MainPage

DataService dataService;
        List<Liberacao> lib;
        double _idorcamento = 0d;
        LiberacaoRepository lRepository = new LiberacaoRepository();

        public MainPage()
    {
        InitializeComponent();
        try
        {
            dataService = new DataService();

            AtualizaDados();
            //Content = new ScrollView { Content = listaLibera, Orientation = ScrollOrientation.Both };
        }
        catch(Exception ex)
        {
            string erro = ex.Message;
        }
    }

    private async void AtualizaDados()
    {
        try
        {
            lib = await dataService.GetLiberaAsync();
            //listaLibera.ItemsSource = lib.OrderBy(item => item.Cliente).ToList();
            dataGrid.ItemsSource = lib.OrderBy(item => item.Cliente).ToList(); //lRepository.OrderInfoCollection;
        }
        catch (Exception ex)
        {
            string erro = ex.Message;
        }
    }

I know I'm missing something in this code, but I do not know what it is

    
asked by anonymous 09.10.2017 / 12:40

1 answer

0

I was able to do this:

SfDataGrid dataGrid;
        DataService dataService = new DataService();
        public App()
        {
            InitializeComponent();

            dataGrid = new SfDataGrid();
            MainPage = new ContentPage { Content = dataGrid };
            this.CriaDataGrid();

            //MainPage = new Autorizador.MainPage();
            //MainPage = new NavigationPage(new Autorizador.MainPage());
        }

        public async void CriaDataGrid()
        {
            dataGrid.AutoGenerateColumns = false;

            GridTextColumn dataLib = new GridTextColumn();
            dataLib.MappingName = "DataLib";
            dataLib.HeaderText = "Data";
            dataLib.Width = 80;
            dataLib.TextAlignment = TextAlignment.Center;

            GridTextColumn cliente = new GridTextColumn();
            cliente.MappingName = "Cliente";
            cliente.HeaderText = "Cliente";
            cliente.Width = 180;
            cliente.TextAlignment = TextAlignment.Center;

            GridTextColumn vendedor = new GridTextColumn();
            vendedor.MappingName = "Vendedor";
            vendedor.HeaderText = "Vendedor";
            vendedor.Width = 180;
            vendedor.TextAlignment = TextAlignment.Center;

            GridTextColumn filial = new GridTextColumn();
            filial.MappingName = "Filial";
            filial.HeaderText = "Filial";
            filial.Width = 100;
            filial.TextAlignment = TextAlignment.Center;

            dataGrid.Columns.Add(dataLib);
            dataGrid.Columns.Add(cliente);
            dataGrid.Columns.Add(vendedor);
            dataGrid.Columns.Add(filial);

            //dataGrid.AllowResizingColumn = true;
            dataGrid.ItemsSource = await dataService.GetLiberaAsync();
        }
    
09.10.2017 / 20:39