Skip to content

Commit 668fda2

Browse files
committed
[working-with] listview context, convert to Observable
1 parent 80df576 commit 668fda2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

WorkingWithListview/WorkingWithListview/App.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public App ()
3333
tabsXaml.Children.Add (new ContextActionsXaml {Title="ContextX", Icon = "xaml.png" });
3434
tabsXaml.Children.Add (new CustomCellXaml {Title="ButtonX", Icon = "xaml.png" });
3535

36-
//MainPage = tabsXaml;
36+
MainPage = tabsXaml;
3737

3838
}
3939
}

WorkingWithListview/WorkingWithListview/Context/ContextActionsXaml.xaml.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33

44
using Xamarin.Forms;
55
using System.Diagnostics;
6+
using System.Collections.ObjectModel;
67

78
namespace WorkingWithListview
89
{
910
public partial class ContextActionsXaml : ContentPage
1011
{
1112

12-
List<string> items;
13+
ObservableCollection<string> items;
1314
public ContextActionsXaml ()
1415
{
1516
InitializeComponent ();
1617

17-
items = new List<string> { "alpha", "beta", "gamma", "delta", "epsilon" };
18-
listView.ItemsSource = items;
18+
items = new ObservableCollection<string> { "alpha", "beta", "gamma", "delta", "epsilon" };
19+
//listView.ItemsSource = items;
20+
listView.SetBinding (ListView.ItemsSourceProperty, new Binding ("."));
21+
listView.BindingContext = items;
1922
}
2023

2124
public void OnItemSelected (object sender, SelectedItemChangedEventArgs e) {
@@ -35,7 +38,6 @@ public void OnDelete (object sender, EventArgs e) {
3538

3639
Debug.WriteLine ("delete " + mi.CommandParameter.ToString ());
3740
items.Remove (mi.CommandParameter.ToString());
38-
listView.ItemsSource = items;
3941
}
4042
}
4143
}

0 commit comments

Comments
 (0)