Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

ListView default scroll amount

$
0
0

Hey guys fairly new guy here, so take it easy on me.

Using Xamarin.Forms, running on an iPad. Have a MasterDetailPage with a ListView in the master part. When you open up the MasterDetailPage, the ListView is scrolled such that the default selected item is only half visible, with half of it above the bounds of the ListView. Is this something I did/can fix or a xamarin bug? Any suggestions would be welcomed. I've included the MasterDetailPage code below.

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Xamarin.Forms;
using DAL;
using BusinessLayer.Engine;

namespace SHHHHHH
{
    class ReadDocumentPage : MasterDetailPage
    {
        EngineInterface engine;
        public ReadDocumentPage(EngineInterface eng)
        {
            engine = eng;
            Label header = new Label
            {
                Text = "Table of Contents",
                Font = Font.BoldSystemFontOfSize(30),
                HorizontalOptions = LayoutOptions.Center
            };

            // Assemble an array of Section objects.
            ObservableCollection<Section> sections = engine.Sections;

            //Create ListView for the master page.
            ListView listView = new ListView
            {
                ItemsSource = sections,
                VerticalOptions = LayoutOptions.Fill
            };

            listView.ItemTemplate = new DataTemplate(typeof(TextCell));
            listView.ItemTemplate.SetBinding(TextCell.TextProperty, "secNumAndTitle");

            // Create the master page with the ListView.
            this.Master = new ContentPage
            {

                Title = "ReadDocumentPage",

                Content = new StackLayout
                {
                    Children = 
                    {
                        listView, 
                        header
                    }
                }
            };
            this.Detail = new ContentPage
            {
                Title = "ReadDocumentPage"
            };

            //Detail page information layout
           /* Label detailHeader = new Label
            {
                Font = Font.BoldSystemFontOfSize(30),
                HorizontalOptions = LayoutOptions.Center
            };
            detailHeader.SetBinding(Label.TextProperty, "secNumAndTitle");
            */
            /*Label description = new Label
            {
                Font = Font.BoldSystemFontOfSize(15),
                HorizontalOptions = LayoutOptions.Fill
            };
            description.SetBinding(Label.TextProperty, "Text");
            */

            //Webview
           /* 
            var template = new DescriptionView() { Model = sections[2] };
            var page = template.GenerateString();
            var description = new WebView();
            var html = new HtmlWebViewSource { Html = page };

            if (Device.OS != TargetPlatform.iOS)
            {
                //IOS is using a custom renderer , Android implements IBaseUrl
                html.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
            }
            description.Source = html;
            */
            //var description = new WebView();
            // Create the detail page using DocumentSections
            //this.Detail = new SectionDetailPage();


            // For Windows Phone, provide a way to get back to the master page.
            if (Device.OS == TargetPlatform.WinPhone)
            {
                (this.Detail as ContentPage).Content.GestureRecognizers.Add(
                    new TapGestureRecognizer((view) =>
                    {
                        this.IsPresented = true;
                    }));
            }

            // Define a selected handler for the ListView.
            listView.ItemSelected += (sender, args) =>
            {
                engine.CurrentSection = (Section)args.SelectedItem;
                //Create WebView Page
                this.Detail = new SectionDetailPage(args);

                // Set the BindingContext of the detail page.
                this.Detail.BindingContext = args.SelectedItem;

                // Show the detail page.
                this.IsPresented = false;
            };

            // Initialize the ListView selection.
            listView.SelectedItem = engine.CurrentSection;

        }
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>