Skip to content

Commit 33e7ff0

Browse files
authored
ReadMe file updated with KB link
1 parent fcfdbcb commit 33e7ff0

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

README.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
# How-to-disable-button-action-when-dragging-listview-item
1+
# How to handle button action of ListView item when dragging in Xamarin.Forms (SflistView)?
22

3-
You can disable the button click action which loaded in ItemTemplate by maintaining a property in the view model and skip the process using Xamarin.Forms Listview when Drag and Drop ListViewItem.
3+
You can handle the button click action that is loaded in the [ItemTemplate](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~ItemTemplate.html?) by maintaining a property in the **ViewModel** and skip the process while drag and drop the [ListViewItem](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.ListViewItem.html?) using Xamarin.Forms SfListView.
44

5-
```
5+
You can also refer the following article.
6+
7+
https://www.syncfusion.com/kb/11686/how-to-handle-button-action-of-listview-item-when-dragging-in-xamarin-forms-sflistview
8+
9+
**XAML**
10+
11+
Bind Button.Command](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/button#using-the-command-interface) to skip the button click action.
12+
``` xml
613
<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms">
714
<ContentPage.Content>
815
<Grid>
916
<syncfusion:SfListView x:Name="listView"
1017
ItemSize="70"
1118
DragStartMode="OnHold"
1219
SelectionBackgroundColor="Transparent"
13-
ItemsSource="{Binding ContactsInfo}">
20+
ItemsSource="{Binding ContactsInfo}">
21+
<syncfusion:SfListView.Behaviors>
22+
<local:Behavior/>
23+
</syncfusion:SfListView.Behaviors>
1424
<syncfusion:SfListView.ItemTemplate>
1525
<DataTemplate>
1626
<ViewCell>
@@ -27,46 +37,69 @@ You can disable the button click action which loaded in ItemTemplate by maintain
2737
</ContentPage.Content>
2838
</ContentPage>
2939
```
40+
**C#**
3041

31-
```
32-
listview.ItemDragging += Listview_ItemDragging;
42+
Behavior class to trigger the [SfListView.ItemDragging](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~ItemDragging_EV.html?) event. Update the property **isDragEndRaised** to **true**, based on the [DragAction](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.ItemDraggingEventArgs~Action.html?).
3343

44+
``` c#
45+
class Behavior : Behavior<SfListView>
46+
{
47+
public SfListView listview { get; private set; }
48+
protected override void OnAttachedTo(SfListView bindable)
49+
{
50+
base.OnAttachedTo(bindable);
51+
listview = bindable as SfListView;
52+
listview.ItemDragging += Listview_ItemDragging;
53+
}
54+
3455
private void Listview_ItemDragging(object sender, ItemDraggingEventArgs e)
3556
{
57+
var viewModel = (sender as SfListView).BindingContext as ListViewGroupingViewModel;
3658
if (e.Action == Syncfusion.ListView.XForms.DragAction.Drop)
3759
{
3860
viewModel.isDragEndRaised = true;
3961
}
4062
}
63+
64+
protected override void OnDetachingFrom(SfListView bindable)
65+
{
66+
base.OnDetachingFrom(bindable);
67+
listview.ItemDragging -= Listview_ItemDragging;
68+
listview = null;
69+
}
70+
}
4171
```
72+
**C#**
4273

43-
Below code defines you to execute the Button command based on DragAction.
44-
45-
```
74+
Disable the isDragEndRaised property in the **TapCommand** execution method.
75+
``` c#
4676
public class ListViewGroupingViewModel
4777
{
4878
private Command tapcommand;
49-
public bool isDragEndRaised = false;
50-
5179
public Command TapCommand
5280
{
5381
get { return tapcommand; }
5482
set { tapcommand = value; }
5583
}
56-
57-
TapCommand = new Command(OnButtonClick);
58-
84+
public bool isDragEndRaised = false;
85+
86+
public ListViewGroupingViewModel()
87+
{
88+
TapCommand = new Command(OnButtonClick);
89+
GenerateSource();
90+
}
91+
5992
private void OnButtonClick(object obj)
6093
{
6194
var itemData = obj as ListViewContactsInfo;
62-
95+
6396
if (isDragEndRaised == true)
6497
{
6598
isDragEndRaised = false;
6699
return;
67100
}
68101
else
69-
App.Current.MainPage.DisplayAlert("Messsage", "Tapped item data : " + itemData.ContactName, "OK");
102+
App.Current.MainPage.DisplayAlert("", "Tapped item data : " + itemData.ContactName, "OK");
70103
}
71104
}
72105
```

0 commit comments

Comments
 (0)