Skip to content

Commit 80df576

Browse files
committed
[working-with] listview context improve behavior
1 parent 87daf2d commit 80df576

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

WorkingWithListview/WorkingWithListview/Context/ContextActionsXaml.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<DataTemplate>
1010
<ViewCell>
1111
<ViewCell.ContextActions>
12-
<MenuItem Clicked="OnMore"
12+
<MenuItem Clicked="OnMore" CommandParameter="{Binding .}"
1313
Text="More" />
14-
<MenuItem Clicked="OnDelete"
14+
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
1515
Text="Delete" IsDestructive="True" />
1616
</ViewCell.ContextActions>
1717
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">

WorkingWithListview/WorkingWithListview/Context/ContextActionsXaml.xaml.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
using System.Collections.Generic;
33

44
using Xamarin.Forms;
5+
using System.Diagnostics;
56

67
namespace WorkingWithListview
78
{
89
public partial class ContextActionsXaml : ContentPage
910
{
11+
12+
List<string> items;
1013
public ContextActionsXaml ()
1114
{
1215
InitializeComponent ();
1316

14-
listView.ItemsSource = new [] { "alpha", "beta", "gamma", "delta" };
17+
items = new List<string> { "alpha", "beta", "gamma", "delta", "epsilon" };
18+
listView.ItemsSource = items;
1519
}
1620

1721
public void OnItemSelected (object sender, SelectedItemChangedEventArgs e) {
@@ -27,7 +31,11 @@ public void OnMore (object sender, EventArgs e) {
2731

2832
public void OnDelete (object sender, EventArgs e) {
2933
var mi = ((MenuItem)sender);
30-
DisplayAlert("Delete Context Action", mi.CommandParameter + " delete context action", "OK");
34+
//DisplayAlert("Delete Context Action", mi.CommandParameter + " delete context action", "OK");
35+
36+
Debug.WriteLine ("delete " + mi.CommandParameter.ToString ());
37+
items.Remove (mi.CommandParameter.ToString());
38+
listView.ItemsSource = items;
3139
}
3240
}
3341
}

0 commit comments

Comments
 (0)