Example #1
0
        private void setupRowActions()
        {
            // Define the context actions
            var deleteAction = new Xamarin.Forms.MenuItem
            {
                Text          = "Delete",
                IsDestructive = true
            }; // red background

            deleteAction.SetBinding(Xamarin.Forms.MenuItem.CommandParameterProperty, new Binding("id"));
            deleteAction.Clicked += async(sender, e) =>
            {
                var mi = ((Xamarin.Forms.MenuItem)sender);

                var recId = (int)mi.CommandParameter;

                TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

                await Task.Factory.StartNew(async() =>
                {
                    // Call the webservice for vehicle makes list
                    var deleteResult = await WorkService.delete(recId);
                    if (!deleteResult.isOK)
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await App.AppMainWindow.DisplayAlert("Error", "Failed to delete the work record: " + deleteResult.error, "OK");
                        });

                        // Done with waiting
                        tcs.SetResult(false);
                        return;
                    }

                    // Done with waiting
                    tcs.SetResult(true);
                });


                // Wait for the delete operation to finish
                bool result = await tcs.Task;
                if (result)
                {
                    var removedData = this.BindingContext as Record;
                    if (removedData == null)
                    {
                        return;
                    }

                    // Acquire the list context
                    WorkListView lvParent = (removedData.context as WorkListView);

                    // Motify the list of changes
                    lvParent.itemDeleted(removedData);
                }
            };

            // add to the ViewCell's ContextActions property
            ContextActions.Add(deleteAction);
        }
Example #2
0
        /**
         * Setup the UI controls and the layout
         */
        private void setupUI()
        {
            //The actual devices list
            lvWork = new WorkListView()
            {
                HorizontalOptions   = LayoutOptions.Fill,
                VerticalOptions     = LayoutOptions.Fill,
                SeparatorVisibility = SeparatorVisibility.Default,
                SeparatorColor      = Color.FromHex("6a6f7b"),
                RowHeight           = 60,
                HasUnevenRows       = true
            };

            ContentEx = lvWork;
        }