本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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
}
};
}
示例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 );
//.........这里部分代码省略.........
示例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 = {
//.........这里部分代码省略.........