Inheritance: Cirrious.MvvmCross.Binding.Touch.Views.MvxBindableTableViewSource
示例#1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            buttonLogout = new UIBarButtonItem("Logout", UIBarButtonItemStyle.Bordered, (s, e) => {
                this.ViewModel.Logout();
            });

            this.Title = "Wish Lists";

            this.NavigationItem.LeftBarButtonItem = buttonLogout;

            this.SetToolbarItems(new UIBarButtonItem[]
            {
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                buttonAdd
            }, false);

            var source = new MvxDeleteBindableTableViewSource(
                this.TableView,
                UITableViewCellStyle.Subtitle,
                new NSString("LoginView"),
                "{'TitleText':{'Path':'Name'}, 'DetailText':{'Path':'Description'}}",
                UITableViewCellAccessory.DisclosureIndicator);


            this.AddBindings(new Dictionary <object, string> ()
            {
                { source, "{'ItemsSource':{'Path':'Lists'}}" }
            });

            source.SelectionChanged += (sender, e) =>
            {
                var path = this.TableView.IndexPathForSelectedRow;
                var list = this.ViewModel.Lists[path.Row];

                this.InvokeOnMainThread(() => this.TableView.DeselectRow(path, true));

                this.ViewModel.Select(list);
            };

            source.OnShouldCommitEditingStyle += (UITableView tv, UITableViewCellEditingStyle style, NSIndexPath indexPath) => {
                var list = this.ViewModel.Lists[indexPath.Row];

                this.ViewModel.Delete(list);
            };


            this.buttonAdd.Clicked += (sender, e) =>
            {
                this.ViewModel.Add();
            };

            this.TableView.Source = source;
            this.TableView.ReloadData();
        }
示例#2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Loading...";

            var source = new MvxDeleteBindableTableViewSource(this.TableView, UITableViewCellStyle.Subtitle,
                                                              new NSString("ListView"), "{'TitleText':{'Path':'Name'}, 'DetailText':{'Path':'Notes'}}",
                                                              UITableViewCellAccessory.DisclosureIndicator);

            this.AddBindings(new Dictionary <object, string>()
            {
                { source, "{'ItemsSource':{'Path':'Entries'}}" }
            });

            source.SelectionChanged += (sender, e) =>
            {
                var path  = TableView.IndexPathForSelectedRow;
                var entry = ViewModel.Entries [path.Row];

                this.InvokeOnMainThread(() => TableView.DeselectRow(path, true));

                this.ViewModel.Select(entry);
            };

            source.OnShouldCommitEditingStyle += (UITableView tv, UITableViewCellEditingStyle style, NSIndexPath indexPath) =>
            {
                var entry = ViewModel.Entries [indexPath.Row];

                ViewModel.Delete(entry);
            };

            buttonEdit.Clicked += (sender, e) => ViewModel.EditWishList();
            buttonAdd.Clicked  += (sender, e) => ViewModel.Add();
            buttonShare         = new UIBarButtonItem("Share", UIBarButtonItemStyle.Bordered, (s, e) => ViewModel.Share());

            NavigationItem.RightBarButtonItem = buttonEdit;

            SetToolbarItems(new UIBarButtonItem[]
            {
                buttonShare,
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                buttonAdd
            }, false);

            TableView.Source = source;
            TableView.ReloadData();
        }