Search code examples
xamarin.androidswipesyncfusion

How to execute a function when sliding right or left? Xamarin Android Syncfusion


Today I downloaded the syncfusion tools, and managed to use a data grid with the sliding property, now I want to know how to execute a function when I slide right or left, could someone give me an example?

this is my code

 protected override void OnCreate(Bundle savedInstanceState)
        {

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.CompartirVale);

            btnDel = FindViewById<Button>(Resource.Id.btnDelShared);
            btnAl = FindViewById<Button>(Resource.Id.btnAlShared);
            btnBuscarRelacionPago = FindViewById<Button>(Resource.Id.btnBuscarValeShared);
            //
            RelativeLayout layout = (RelativeLayout)FindViewById(Resource.Id.RelativeCompartirVale);
            imgPDF = FindViewById<ImageView>(Resource.Id.imgPDFShared);
            imgwhats = FindViewById<ImageView>(Resource.Id.imgWhatsApp);
            dataGrid = new SfDataGrid(BaseContext);
            layout.AddView(dataGrid);
            this.dataGrid.AllowSwiping = true;

            OrderInfoRepository viewModel = new OrderInfoRepository();
            dataGrid.ItemsSource = viewModel.OrderInfoCollection;
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            //
            SwipeView leftSwipeView = new SwipeView(BaseContext);
            SwipeView rightSwipeView = new SwipeView(BaseContext);
            LinearLayout editView = new LinearLayout(BaseContext);
            LinearLayout deleteView = new LinearLayout(BaseContext);

            ImageView editImage = new ImageView(BaseContext);
            editImage.SetImageResource(Resource.Drawable.whatsapp);
            editImage.SetBackgroundColor(Color.ParseColor("#FFFFFF"));

            ImageView deleteImage = new ImageView(BaseContext);
            deleteImage.SetImageResource(Resource.Drawable.gmail);
            deleteImage.SetBackgroundColor(Color.ParseColor("#FFFFFF"));

            editView.AddView(editImage, ViewGroup.LayoutParams.MatchParent, (int)dataGrid.RowHeight);
            //editView.AddView(edit, ViewGroup.LayoutParams.MatchParent, (int)dataGrid.RowHeight);

            deleteView.AddView(deleteImage, ViewGroup.LayoutParams.MatchParent, (int)dataGrid.RowHeight);
            //deleteView.AddView(delete, ViewGroup.LayoutParams.MatchParent, (int)dataGrid.RowHeight);

            leftSwipeView.AddView(editView, dataGrid.MaxSwipeOffset, (int)dataGrid.RowHeight);
            rightSwipeView.AddView(deleteView, dataGrid.MaxSwipeOffset, (int)dataGrid.RowHeight);

            dataGrid.LeftSwipeView = leftSwipeView;
            dataGrid.RightSwipeView = rightSwipeView;
            //
        }

What event is executed when I slide the line to the right or to the left?


Solution

  • In SfDataGrid, three events will be raised while swiping. If you start the swiping process, then SwipeStarted event will be raised. If the swiping is in progress, then Swiping event will be raised. If the swiping operation is ended, then SwipeEnded event will be raised. Please refer the below code snippet,

    dataGrid.SwipeStarted += DataGrid_SwipeStarted;
    dataGrid.Swiping += DataGrid_Swiping;
    dataGrid.SwipeEnded += DataGrid_SwipeEnded;
    
    //Swipe ended event will fire once you the swiping process is ended
    private void DataGrid_SwipeEnded(object sender, SwipeEndedEventArgs e)
    {
    
    }
    //Swiping event will fire when the swiping process is in progress
    private void DataGrid_Swiping(object sender, SwipingEventArgs e)
    {
    
    }      
    //Swipe started event will fire once you started the swiping process
    private void DataGrid_SwipeStarted(object sender, SwipeStartedEventArgs e)
    {
    
    }
    

    Please refer the below UG link to know more about SfDataGrid swiping feature and its events, UG link: https://help.syncfusion.com/xamarin-android/sfdatagrid/swiping

    Also, we have prepared a sample using swiping feature and you can download the same from the below link, Sample link: http://www.syncfusion.com/downloads/support/forum/132930/ze/Sample1951506069

    Regards, Divakar.