public iOSListViewWithCellPageCS()
        {
            var personDataTemplate = new DataTemplate(() =>
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.7, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.3, GridUnitType.Star)
                });

                var nameLabel = new Label();
                var ageLabel  = new Label {
                    HorizontalOptions = LayoutOptions.End
                };

                nameLabel.SetBinding(Label.TextProperty, "Name");
                ageLabel.SetBinding(Label.TextProperty, "Age");

                grid.Children.Add(nameLabel);
                grid.Children.Add(ageLabel, 1, 0);

                return(new ViewCell {
                    View = grid
                });
            });

            var groupHeaderTemplate = new DataTemplate(() =>
            {
                var label = new Label {
                    Margin = new Thickness(10, 10), FontAttributes = FontAttributes.Bold
                };
                label.SetBinding(Label.TextProperty, "Key");

                var viewCell = new ViewCell {
                    View = label
                };
                viewCell.On <iOS>().SetDefaultBackgroundColor(Color.Teal);
                return(viewCell);
            });

            var listView = new Xamarin.Forms.ListView {
                IsGroupingEnabled = true, ItemTemplate = personDataTemplate, GroupHeaderTemplate = groupHeaderTemplate
            };

            listView.SetBinding(ItemsView <Xamarin.Forms.Cell> .ItemsSourceProperty, "GroupedEmployees");
            listView.On <iOS>()
            .SetSeparatorStyle(SeparatorStyle.FullWidth)
            .SetRowAnimationsEnabled(false)
            .SetGroupHeaderStyle(GroupHeaderStyle.Grouped);

            Title   = "ListView/Cell Platform-Specifics";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children = { listView }
            };
            BindingContext = new ListViewViewModel(20);
        }
        public iOSPanGestureRecognizerPageCS()
        {
            Xamarin.Forms.Application.Current.On <iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(true);

            var messageLabel = new Label {
                Text = "Scroll the list. If you touch the age Label, this Label will change", FontAttributes = FontAttributes.Bold
            };
            var toggleButton = new Button {
                Text = "Toggle Simultaneous Gesture Recognition"
            };

            toggleButton.Clicked += (sender, e) =>
                                    Xamarin.Forms.Application.Current.On <iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(
                !Xamarin.Forms.Application.Current.On <iOS>().GetPanGestureRecognizerShouldRecognizeSimultaneously());

            var personDataTemplate = new DataTemplate(() =>
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.7, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.3, GridUnitType.Star)
                });

                var nameLabel = new Label();
                nameLabel.SetBinding(Label.TextProperty, "Name");

                var ageLabel = new Label {
                    HorizontalOptions = LayoutOptions.End
                };
                ageLabel.SetBinding(Label.TextProperty, "Age");
                var panGestureRecognizer         = new PanGestureRecognizer();
                panGestureRecognizer.PanUpdated += (sender, e) => messageLabel.Text = $"panned x:{e.TotalX} y:{e.TotalY}";;
                ageLabel.GestureRecognizers.Add(panGestureRecognizer);

                grid.Children.Add(nameLabel);
                grid.Children.Add(ageLabel, 1, 0);

                return(new ViewCell {
                    View = grid
                });
            });

            var listView = new Xamarin.Forms.ListView {
                IsGroupingEnabled = true, ItemTemplate = personDataTemplate
            };

            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees");
            listView.GroupDisplayBinding = new Binding("Key");

            Title   = "Pan Gesture Recognizer";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children = { messageLabel, toggleButton, listView }
            };
            BindingContext = new ListViewViewModel();
        }
        public AndroidListViewFastScrollPageCS()
        {
            var personDataTemplate = new DataTemplate(() =>
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.7, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.3, GridUnitType.Star)
                });

                var nameLabel = new Label();
                var ageLabel  = new Label {
                    HorizontalOptions = LayoutOptions.End
                };

                nameLabel.SetBinding(Label.TextProperty, "Name");
                ageLabel.SetBinding(Label.TextProperty, "Age");

                grid.Children.Add(nameLabel);
                grid.Children.Add(ageLabel, 1, 0);

                return(new Xamarin.Forms.ViewCell {
                    View = grid
                });
            });

            var listView = new Xamarin.Forms.ListView {
                IsGroupingEnabled = true, ItemTemplate = personDataTemplate
            };

            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees");
            listView.GroupDisplayBinding = new Binding("Key");
            listView.On <Android>().SetIsFastScrollEnabled(true);

            var button = new Xamarin.Forms.Button {
                Text = "Toggle FastScroll"
            };

            button.Clicked += (sender, e) => { listView.On <Android>().SetIsFastScrollEnabled(!listView.On <Android>().IsFastScrollEnabled()); };

            Title   = "ListView FastScroll";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children =
                {
                    button,
                    listView
                }
            };
            BindingContext = new ListViewViewModel();
        }
Exemplo n.º 4
0
        public iOSListViewPageCS()
        {
            var personDataTemplate = new DataTemplate(() =>
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.7, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.3, GridUnitType.Star)
                });

                var nameLabel = new Label();
                var ageLabel  = new Label {
                    HorizontalOptions = LayoutOptions.End
                };

                nameLabel.SetBinding(Label.TextProperty, "Name");
                ageLabel.SetBinding(Label.TextProperty, "Age");

                grid.Children.Add(nameLabel);
                grid.Children.Add(ageLabel, 1, 0);

                return(new ViewCell {
                    View = grid
                });
            });

            var listView = new Xamarin.Forms.ListView {
                IsGroupingEnabled = true, ItemTemplate = personDataTemplate
            };

            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees");
            listView.GroupDisplayBinding = new Binding("Key");
            listView.On <iOS>().SetSeparatorStyle(SeparatorStyle.FullWidth);

            Title   = "ListView FullWidth Separators";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children = { listView }
            };
            BindingContext = new ListViewViewModel();
        }
Exemplo n.º 5
0
 public AndroidListViewFastScrollPage()
 {
     InitializeComponent();
     BindingContext = new ListViewViewModel();
 }
        public WindowsListViewPageCS()
        {
            var personDataTemplate = new DataTemplate(() =>
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.7, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.3, GridUnitType.Star)
                });

                var nameLabel = new Xamarin.Forms.Label();
                var ageLabel  = new Xamarin.Forms.Label {
                    HorizontalOptions = LayoutOptions.Center
                };

                nameLabel.SetBinding(Xamarin.Forms.Label.TextProperty, "Name");
                ageLabel.SetBinding(Xamarin.Forms.Label.TextProperty, "Age");

                var tapGestureRecognizer     = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += async(sender, e) =>
                {
                    await DisplayAlert("Tap Gesture Recognizer", "Tapped event fired.", "OK");
                };
                nameLabel.GestureRecognizers.Add(tapGestureRecognizer);

                grid.Children.Add(nameLabel);
                grid.Children.Add(ageLabel, 1, 0);

                return(new ViewCell {
                    View = grid
                });
            });

            _listView = new Xamarin.Forms.ListView {
                IsGroupingEnabled = true, ItemTemplate = personDataTemplate
            };
            _listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees");
            _listView.GroupDisplayBinding = new Binding("Key");
            _listView.ItemTapped         += async(sender, e) =>
            {
                await DisplayAlert("Item Tapped", "ItemTapped event fired.", "OK");
            };
            _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Inaccessible);

            var button = new Button {
                Text = "Toggle SelectionMode"
            };

            button.Clicked += (sender, e) =>
            {
                switch (_listView.On <Windows>().GetSelectionMode())
                {
                case ListViewSelectionMode.Accessible:
                    _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Inaccessible);
                    break;

                case ListViewSelectionMode.Inaccessible:
                    _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Accessible);
                    break;
                }
                UpdateLabel();
            };

            _label = new Xamarin.Forms.Label {
                HorizontalOptions = LayoutOptions.Center
            };

            Title   = "ListView Selection Mode";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children = { _listView, button, _label }
            };
            BindingContext = new ListViewViewModel();
            UpdateLabel();
        }
Exemplo n.º 7
0
 public iOSListViewWithCellPage()
 {
     InitializeComponent();
     BindingContext = new ListViewViewModel(20);
 }
 public WindowsListViewPage()
 {
     InitializeComponent();
     BindingContext = new ListViewViewModel();
     UpdateLabel();
 }
 public iOSPanGestureRecognizerPage()
 {
     InitializeComponent();
     BindingContext = new ListViewViewModel();
 }