Exemplo n.º 1
0
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        void Initialize()
        {
            var layout = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center
            };

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
            Content = layout;

            var loadingPage = new LoadingPage(async(page) =>
            {
                var vm       = ViewModelFactory.Get <RootViewModel>();
                var products = await vm.GetProducts();

                var kv = products.GroupBy(p => p.Category, p => p, (key, value) => new { Key = key, Value = value });

                var tableRoot = new TableRoot();

                foreach (var obj in kv)
                {
                    tableRoot.Add(GetTableSection(obj.Key, obj.Value));
                }

                var tableView = new TableView {
                    Intent = TableIntent.Menu, Root = tableRoot
                };

                page.OnLoaded(tableView);
            }, "Chargement du catalogue");


            loadingPage.Loaded += async(sender, e) => {
                var label = new Label
                {
                    Text              = "T-Shirt shop",
                    FontSize          = 36.0,
                    TextColor         = Color.FromRgb(52, 152, 219),
                    HorizontalOptions = LayoutOptions.Center
                };
                layout.Children.Add(label);
                layout.Children.Add((TableView)e);
                await Navigation.PopModalAsync();
            };
            Navigation.PushModalAsync(loadingPage);
        }
Exemplo n.º 2
0
        void Bind(Product product)
        {
            var viewModel = ViewModelFactory.Get <OrderViewModel>();

            viewModel.Current = product;

            viewModel.Failed += async(sender, e) =>
            {
                await DisplayAlert("Echec de la commande", "Impossible de passer la commande !", "OK");

                await Navigation.PopModalAsync();
            };

            viewModel.Ordered += async(sender, e) =>
            {
                await DisplayAlert("Commande validée", "Merci pour votre achat !", "OK");

                await Navigation.PopModalAsync();
            };

            BindingContext = viewModel;
        }