public ListPage(BaseViewModel <T> viewModel) : base(viewModel)
        {
            this.SetValue(Page.TitleProperty, "List");
            this.SetBinding(Page.IconProperty, "Icon");

            var list = new ListView();

            list.ItemsSource = ViewModel.Models;

#if __ANDROID__
            Cell = new DataTemplate(typeof(ListTextCell));
#else
            Cell = new DataTemplate(typeof(TextCell));
#endif


            Cell.SetBinding(TextCell.TextProperty, "FirstName");
            Cell.SetBinding(TextCell.DetailProperty, "Industry");

            list.ItemTemplate  = Cell;
            list.ItemSelected += (sender, e) =>
            {
                var details = new DetailPage <T>(e.SelectedItem as T);
                Navigation.PushAsync(details);
            };
            var stack = new StackLayout();
            stack.Children.Add(list);
            Content = stack;
        }
예제 #2
0
        public ListPage(BaseViewModel <T> viewModel) : base(viewModel)
        {
            //Set value will directly set the value to "List"
            this.SetValue(Page.TitleProperty, "List");
            //This will bind to our BindingContext.Icon
            this.SetBinding(Page.IconProperty, "Icon");

            var list = new ListView();

            //Bind the items in our list to the observable collection of models
            list.ItemsSource = ViewModel.Models;

            Cell = new DataTemplate(typeof(ListTextCell));

            //Bind our cell's text and details properties
            Cell.SetBinding(TextCell.TextProperty, "FirstName");
            Cell.SetBinding(TextCell.DetailProperty, "Industry");

            list.ItemTemplate = Cell;

            list.ItemSelected += (sender, e) =>
            {
                if (e.SelectedItem == null)
                {
                    return;
                }
                var details = new DetailPage <T>(e.SelectedItem as T);
                Navigation.PushAsync(details);
                //deselect item when pushing
                list.SelectedItem = null;
            };
            var stack = new StackLayout();

            stack.Children.Add(list);
            Content = stack;
        }