当前位置: 首页>>代码示例>>C#>>正文


C# ListView.ScrollTo方法代码示例

本文整理汇总了C#中ListView.ScrollTo方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.ScrollTo方法的具体用法?C# ListView.ScrollTo怎么用?C# ListView.ScrollTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListView的用法示例。


在下文中一共展示了ListView.ScrollTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Scroll

 private void Scroll(ListView lst, bool topOrBottom) {
     if (lst == null || this.Datas == null || this.Datas.Count == 0)
         return;
     if (topOrBottom)
         lst.ScrollTo(this.Datas.First().FirstOrDefault(), this.Datas.First(), ScrollToPosition.Start, true);
     else
         lst.ScrollTo(this.Datas.Last().LastOrDefault(), this.Datas.Last(), ScrollToPosition.End, true);
 }
开发者ID:gruan01,项目名称:Discuz.Mobi,代码行数:8,代码来源:ForumIndexViewModel.cs

示例2: DemoPage

        public DemoPage()
        {
            this.Padding = 0;
            var mainStack = new StackLayout () {
                Padding = new Thickness(0,20,0,0),
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            listView = new ListView () {};
            listView.ItemsSource = items;
            mainStack.Children.Add (listView);

            textEntry = new Entry () {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Placeholder = "Type something...",
            };

            var textStack = new StackLayout () {
                Orientation = StackOrientation.Horizontal,
                Padding = 10,
                BackgroundColor = Color.White,
            };
            textStack.Children.Add (textEntry);

            var textButton = new Button () {
                Text = "Post",
                FontAttributes = FontAttributes.Bold,
                FontSize = 16,
                HorizontalOptions = LayoutOptions.End,
            };

            textButton.Clicked += (object sender, EventArgs e) => {
                System.Diagnostics.Debug.WriteLine ("listview height: " + listView.Height);
                items.Add(textEntry.Text);
                textEntry.Text = string.Empty;
                listView.ScrollTo(items.Last(), ScrollToPosition.MakeVisible, true);
            };
            textStack.Children.Add (textButton);
            mainStack.Children.Add (textStack);

            // This works nicely with stacklayouts but causes issues on listviews as they automatically adjust their size
            //			var spacer = new BoxView () {
            //				HorizontalOptions = LayoutOptions.FillAndExpand,
            //				HeightRequest = 0,
            //			};
            //			mainStack.Children.Add (spacer);

            KeyboardHelper.KeyboardChanged += (sender, e) => {
                bottomOffset = mainStack.Bounds.Bottom - textStack.Bounds.Bottom;	// This offset allows us to only raise the stack by the amount required to stay above the keyboard.
                var ty = e.Visible ? -e.Height : -1;
                textStack.TranslateTo(textStack.TranslationX, ty, e.Duration, Easing.CubicInOut);
            //				spacer.HeightRequest = e.Visible ? e.Height : -1;
            };
            this.Content = mainStack;
        }
开发者ID:naturalistic,项目名称:RaiseKeyboard,代码行数:56,代码来源:DemoPage.cs

示例3: MessagePage

        public MessagePage()
        {
            this.ToolbarItems.Add(new ToolbarItem(){ Text = "Add", Command = new Command(o => AddAnotherItem()) });
            FillMessageList();
            //messageList = messageList.OrderBy(t => t.datestamp.Year).ThenBy(t => t.datestamp.Month).ThenBy(t => t.datestamp.Day).ThenBy(t => t.datestamp.Hour).ThenBy(t => t.datestamp.Minute).ThenBy(t => t.datestamp.Second);
            if (Device.OS == TargetPlatform.iOS)
                this.Padding = new Thickness(0, 20, 0, 0);
            if (Device.OS != TargetPlatform.iOS)
                this.BackgroundColor = Color.White;

            listView = new ListView()
            {
                ItemsSource = messageList,
                ItemTemplate = new DataTemplate(typeof(Messages)),
                HasUnevenRows = true,
            };

            listView.ScrollTo(messageList.Count - 1, ScrollToPosition.End, true);

            Content = listView;
        }
开发者ID:nodoid,项目名称:AddMore,代码行数:21,代码来源:MessagePage.cs

示例4: XamarinListViewScrollToBugPage2

		public XamarinListViewScrollToBugPage2 ()
		{
			Title = "Crash in ScrollToPosition.End";

			for (int i = 0; i < 100; i++) {
				var item = new ListObj { Name = string.Format ("2 {0} {0} {0} {0} {0} {0}", i) };
				_collection.Add (item);
			}

			_listView = new ListView {
				ItemsSource = _collection,
				ItemTemplate = new DataTemplate (typeof(CellTemplateScrollTo))
			};

			var endButton = new Button {
				Text = "ScrollToPosition.End End - Not animated",
				Command = new Command (() => {
					_listView.ScrollTo (_collection.Last(), ScrollToPosition.End, false);
				})
			};

			var endButtonAnimated = new Button {
				Text = "ScrollToPosition.MakeVisible End - Animated",
				Command = new Command (() => {
					_listView.ScrollTo (_collection.Last(), ScrollToPosition.MakeVisible, true);
				})
			};

			Content = new StackLayout {
				Children = {
					endButton,
					endButtonAnimated,
					_listView
				}
			};
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:36,代码来源:Issue2411.cs

示例5: ChatDetailsPage

		public ChatDetailsPage ( ObservableCollection<ChatDetails> chats,string tosusrID, string userImageUrl, string toUserName )
		{


			App.CurrentChatUserID = tosusrID;
			NavigationPage.SetHasNavigationBar(this, false);

			chatList = chats;
			touserID = tosusrID;
			currentuser = App.Settings.GetUser ();

		    timer = DependencyService.Get<IAdvancedTimer>();
			timer.initTimer (30000, SyncChatHistoryFromServer, true);
			timer.startTimer ();
			//Xamarin.Forms.Device.StartTimer ( TimeSpan.FromSeconds( 1 ), SyncChatHistoryFromServer );


			string chatTouser = toUserName;

			if (chatTouser.Length > 30)
			{
				chatTouser = chatTouser.Substring(0, 30);
				chatTouser += "...";
			}


			progressBar = DependencyService.Get< IProgressBar > ();
			mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), chatTouser, Color.Black, userImageUrl, true);
			mainTitleBar.imageAreaTapGestureRecognizer.Tapped += (object sender, EventArgs e) => 
			{
				App.masterPage.IsPresented = true;
			};
			subTitleBar = new CommunityGemChatTitleBar(Constants.SUB_TITLE_BG_COLOR, chatTouser, userImageUrl, false);
			subTitleBar.BackButtonTapRecognizer.Tapped += async (object sender, EventArgs e) => 
			{
				timer.stopTimer ();
				App.CurrentChatUserID = null;
				await Navigation.PopAsync();
			};

			masterLayout = new CustomLayout ();
			masterLayout.WidthRequest = App.screenWidth;
			masterLayout.HeightRequest = App.screenHeight - 50;
			masterLayout.BackgroundColor = Color.FromRgb(45, 62, 80);

			chatHistoryListView = new ListView();
			chatHistoryListView.ItemTemplate = new DataTemplate(typeof(ChatHistoryListCell));
			chatHistoryListView.SeparatorVisibility = SeparatorVisibility.None;
			chatHistoryListView.HeightRequest = App.screenHeight * 70 / 100;
			chatHistoryListView.HasUnevenRows = true;
			chatHistoryListView.BackgroundColor =  Color.FromRgb(54, 79, 120);
			chatHistoryListView.ItemsSource = chatList;
			if( chatList != null && chatList.Count > 1 )
				chatHistoryListView.ScrollTo( chatList[ chatList.Count -1 ], ScrollToPosition.End, true );
			
			chatHistoryListView.ItemTapped += (object sender, ItemTappedEventArgs e) => 
			{
				chatHistoryListView.SelectedItem = null;
			};
			chatHistoryListView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => 
			{
				chatHistoryListView.SelectedItem = null;
			};


		

			ExtendedEntry chatEntry = new ExtendedEntry
			{
				Placeholder = "Enter your chat...",
				BackgroundColor = Color.White,//Color.White,
				WidthRequest = App.screenWidth * .80,
				HorizontalOptions = LayoutOptions.Start,
				TextColor = Color.Black
			};
			chatEntry.TextChanged += ChatEntry_TextChanged;

			Image postChatButton = new Image();
			postChatButton.Source = Device.OnPlatform("icon_send.png", "icon_send.png", "//Assets//icon_send.png");

			postChatButton.VerticalOptions = LayoutOptions.Center;
			postChatButton.HorizontalOptions = LayoutOptions.Center;
			TapGestureRecognizer postChatButtonTap = new TapGestureRecognizer();

			postChatButton.GestureRecognizers.Add(postChatButtonTap);

			StackLayout inputCountainer = new StackLayout
			{
				Spacing = Device.OnPlatform(5, 5, 1),
				Padding = Device.OnPlatform(5, 5, 5),
				Orientation = StackOrientation.Horizontal,
				BackgroundColor = Color.FromRgb( 45, 62, 80 ),
				Children = { chatEntry, postChatButton },
				WidthRequest = App.screenWidth
			};


			masterLayout.AddChildToLayout(mainTitleBar, 0, 0);
			masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 10));
			masterLayout.AddChildToLayout ( chatHistoryListView, 0, 17 );
//.........这里部分代码省略.........
开发者ID:praveenmohanmm,项目名称:PurposeColor_Bkp_Code,代码行数:101,代码来源:ChatDetailsPage.cs

示例6: Init

		protected override void Init ()
		{
			var people = new ObservableCollection<Person> {
				new Person ("Abigail", new DateTime (1975, 1, 15), Color.Aqua),
				new Person ("Bob", new DateTime (1976, 2, 20), Color.Black),
				new Person ("Cathy", new DateTime (1977, 3, 10), Color.Blue),
#pragma warning disable 618
				new Person ("David", new DateTime (1978, 4, 25), Color.Fuschia),
#pragma warning restore 618
			};

			var buttonAdd = new Button {
				Text = "Add",
				HorizontalOptions = LayoutOptions.Start,
				VerticalOptions = LayoutOptions.Center,
			};

			var buttonRemove = new Button {
				Text = "Remove",
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.Center,
			};

			var buttonScrollToBottom = new Button {
				Text = "Bottom",
				HorizontalOptions = LayoutOptions.Start,
				VerticalOptions = LayoutOptions.Center,
			};

			var buttonStack = new StackLayout {
				Orientation = StackOrientation.Horizontal,
				Children = {
					buttonAdd,
					buttonRemove,
					buttonScrollToBottom,
				}
			};

			var listView = new ListView {
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				ItemsSource = people,
				ItemTemplate = new DataTemplate (() =>
				{
					var nameLabel = new Label ();
					var birthdayLabel = new Label ();
					var boxView = new BoxView ();

					var stack = new StackLayout {
						Padding = new Thickness (0, 5),
						Orientation = StackOrientation.Horizontal,
						BackgroundColor = Color.Black,
						Children = {
							boxView,
							new StackLayout {
								VerticalOptions = LayoutOptions.Center,
								Spacing = 0,
								Children = {
									nameLabel,
									birthdayLabel
								}
							}
						}
					};

					nameLabel.SetBinding (Label.TextProperty, "Name");
					birthdayLabel.SetBinding (Label.TextProperty, new Binding ("Birthday", BindingMode.OneWay, null, null, "Born {0:d}"));
					boxView.SetBinding (BoxView.ColorProperty, "FavoriteColor");
					stack.SetBinding (BackgroundColorProperty, "BackgroundColor");

					return new ViewCell {
						View = stack
					};
				})
			};

			buttonAdd.Clicked += (sender, e) =>
			{
				var person = new Person (string.Format ("Name {0}", _count++), DateTime.Today, Color.Blue);

				people.Add (person);

				listView.ScrollTo (person, ScrollToPosition.End, true);

			};

			buttonRemove.Clicked += (sender, e) => people.RemoveAt (people.Count - 1);

			buttonScrollToBottom.Clicked += (sender, e) =>
			{
				var person = people[people.Count - 1];

				listView.ScrollTo (person, ScrollToPosition.End, true);
			};

			Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);

			Content = new StackLayout {
				Orientation = StackOrientation.Vertical,
				Children = {
//.........这里部分代码省略.........
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:101,代码来源:Issue2259.cs


注:本文中的ListView.ScrollTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。