Can't scroll ListView to top on iOS?
up vote
0
down vote
favorite
On Xamarin Forms 3.3, I can't scroll ListView to top on iOS.
I try: Scrolling to start of Xamarin Forms ListView with header
But Can't set scroll ListView to top.
This is my code:
At control iOS:
public class ExtListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e) => iOS.Control.Logger.InvokeAction(() =>
{
base.OnElementChanged(e);
if (!(e.NewElement is ExtListView extListView) || Control == null)
return;
extListView.EventScrollToTop += OnScrollToTop;
});
public void OnScrollToTop(object sender, EventArgs eventArgs)
{
Control.ScrollRectToVisible(new CoreGraphics.CGRect(0, 0, 1, 1), true);
}
}
At class control:
public class ExtListView : ListView
{
public event EventHandler EventScrollToTop;
/// <summary>
/// Scroll LisView To Top
/// </summary>
/// <param name="animate"></param>
public void ScrollToTop(bool animate = true)
{
//bool animate is not used at this stage, it's always animated.
EventScrollToTop?.Invoke(this, EventArgs.Empty);
}
}
At view .xaml:
<control:ExtListView.Behaviors>
<common:MethodToDelegateBehavior Delegate="{Binding ScrollToTop}"
DelegateType="{x:Type propertyViewModels:PropertyPageViewModel+ScrollToTopDelegate}"
MethodName="ScrollToTop" />
</control:ExtListView.Behaviors>
At page:
public delegate void ScrollToTopDelegate(bool animate);
private ScrollToTopDelegate _scrollToTop;
public ScrollToTopDelegate ScrollToTop
{
get => _scrollToTop;
set => this.RaiseAndSetIfChanged(ref _scrollToTop, value);
}
At method use:
ScrollToTop?.Invoke(true);
- I use it on Android is work, but iOS is not work.
listview xamarin xamarin.forms xamarin.ios
add a comment |
up vote
0
down vote
favorite
On Xamarin Forms 3.3, I can't scroll ListView to top on iOS.
I try: Scrolling to start of Xamarin Forms ListView with header
But Can't set scroll ListView to top.
This is my code:
At control iOS:
public class ExtListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e) => iOS.Control.Logger.InvokeAction(() =>
{
base.OnElementChanged(e);
if (!(e.NewElement is ExtListView extListView) || Control == null)
return;
extListView.EventScrollToTop += OnScrollToTop;
});
public void OnScrollToTop(object sender, EventArgs eventArgs)
{
Control.ScrollRectToVisible(new CoreGraphics.CGRect(0, 0, 1, 1), true);
}
}
At class control:
public class ExtListView : ListView
{
public event EventHandler EventScrollToTop;
/// <summary>
/// Scroll LisView To Top
/// </summary>
/// <param name="animate"></param>
public void ScrollToTop(bool animate = true)
{
//bool animate is not used at this stage, it's always animated.
EventScrollToTop?.Invoke(this, EventArgs.Empty);
}
}
At view .xaml:
<control:ExtListView.Behaviors>
<common:MethodToDelegateBehavior Delegate="{Binding ScrollToTop}"
DelegateType="{x:Type propertyViewModels:PropertyPageViewModel+ScrollToTopDelegate}"
MethodName="ScrollToTop" />
</control:ExtListView.Behaviors>
At page:
public delegate void ScrollToTopDelegate(bool animate);
private ScrollToTopDelegate _scrollToTop;
public ScrollToTopDelegate ScrollToTop
{
get => _scrollToTop;
set => this.RaiseAndSetIfChanged(ref _scrollToTop, value);
}
At method use:
ScrollToTop?.Invoke(true);
- I use it on Android is work, but iOS is not work.
listview xamarin xamarin.forms xamarin.ios
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I callScrollToTop
function. Could you please provide more information to reproduce your problem?
– Jack Hua - MSFT
Nov 21 at 3:19
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
On Xamarin Forms 3.3, I can't scroll ListView to top on iOS.
I try: Scrolling to start of Xamarin Forms ListView with header
But Can't set scroll ListView to top.
This is my code:
At control iOS:
public class ExtListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e) => iOS.Control.Logger.InvokeAction(() =>
{
base.OnElementChanged(e);
if (!(e.NewElement is ExtListView extListView) || Control == null)
return;
extListView.EventScrollToTop += OnScrollToTop;
});
public void OnScrollToTop(object sender, EventArgs eventArgs)
{
Control.ScrollRectToVisible(new CoreGraphics.CGRect(0, 0, 1, 1), true);
}
}
At class control:
public class ExtListView : ListView
{
public event EventHandler EventScrollToTop;
/// <summary>
/// Scroll LisView To Top
/// </summary>
/// <param name="animate"></param>
public void ScrollToTop(bool animate = true)
{
//bool animate is not used at this stage, it's always animated.
EventScrollToTop?.Invoke(this, EventArgs.Empty);
}
}
At view .xaml:
<control:ExtListView.Behaviors>
<common:MethodToDelegateBehavior Delegate="{Binding ScrollToTop}"
DelegateType="{x:Type propertyViewModels:PropertyPageViewModel+ScrollToTopDelegate}"
MethodName="ScrollToTop" />
</control:ExtListView.Behaviors>
At page:
public delegate void ScrollToTopDelegate(bool animate);
private ScrollToTopDelegate _scrollToTop;
public ScrollToTopDelegate ScrollToTop
{
get => _scrollToTop;
set => this.RaiseAndSetIfChanged(ref _scrollToTop, value);
}
At method use:
ScrollToTop?.Invoke(true);
- I use it on Android is work, but iOS is not work.
listview xamarin xamarin.forms xamarin.ios
On Xamarin Forms 3.3, I can't scroll ListView to top on iOS.
I try: Scrolling to start of Xamarin Forms ListView with header
But Can't set scroll ListView to top.
This is my code:
At control iOS:
public class ExtListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e) => iOS.Control.Logger.InvokeAction(() =>
{
base.OnElementChanged(e);
if (!(e.NewElement is ExtListView extListView) || Control == null)
return;
extListView.EventScrollToTop += OnScrollToTop;
});
public void OnScrollToTop(object sender, EventArgs eventArgs)
{
Control.ScrollRectToVisible(new CoreGraphics.CGRect(0, 0, 1, 1), true);
}
}
At class control:
public class ExtListView : ListView
{
public event EventHandler EventScrollToTop;
/// <summary>
/// Scroll LisView To Top
/// </summary>
/// <param name="animate"></param>
public void ScrollToTop(bool animate = true)
{
//bool animate is not used at this stage, it's always animated.
EventScrollToTop?.Invoke(this, EventArgs.Empty);
}
}
At view .xaml:
<control:ExtListView.Behaviors>
<common:MethodToDelegateBehavior Delegate="{Binding ScrollToTop}"
DelegateType="{x:Type propertyViewModels:PropertyPageViewModel+ScrollToTopDelegate}"
MethodName="ScrollToTop" />
</control:ExtListView.Behaviors>
At page:
public delegate void ScrollToTopDelegate(bool animate);
private ScrollToTopDelegate _scrollToTop;
public ScrollToTopDelegate ScrollToTop
{
get => _scrollToTop;
set => this.RaiseAndSetIfChanged(ref _scrollToTop, value);
}
At method use:
ScrollToTop?.Invoke(true);
- I use it on Android is work, but iOS is not work.
listview xamarin xamarin.forms xamarin.ios
listview xamarin xamarin.forms xamarin.ios
asked Nov 20 at 14:50
Huu Bao Nguyen
8112
8112
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I callScrollToTop
function. Could you please provide more information to reproduce your problem?
– Jack Hua - MSFT
Nov 21 at 3:19
add a comment |
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I callScrollToTop
function. Could you please provide more information to reproduce your problem?
– Jack Hua - MSFT
Nov 21 at 3:19
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I call
ScrollToTop
function. Could you please provide more information to reproduce your problem?– Jack Hua - MSFT
Nov 21 at 3:19
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I call
ScrollToTop
function. Could you please provide more information to reproduce your problem?– Jack Hua - MSFT
Nov 21 at 3:19
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
This is my idea:
- Use method
ScrollTo
of ClassListView
(ScrollTo). - Set item focus on
ListView
is first item andScrollToPosition
isScrollToPosition.Start
(use animated = true
if you want to see the scroll happen)
Create a flag: ScrollToTop = true
use at layout .xaml that handler change Scroll of ListView.
You try it:
var firstItem = ((IEnumerable<object>)extListView.ItemsSource)?.FirstOrDefault();
if (firstItem != null)
extListView.ScrollTo(firstItem, ScrollToPosition.Start, false);
Hope it can help you!
add a comment |
up vote
1
down vote
I use the following code to scroll my ListView classes to a specific position.
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, y), animated);
When scrolling, X normally will not change, but Y is the value you would like changed. Using that code scrolling to the top would be like this:
// You can send true for the animate property whether or not you want to see the scroll happen
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, 0), true);
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395591%2fcant-scroll-listview-to-top-on-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
This is my idea:
- Use method
ScrollTo
of ClassListView
(ScrollTo). - Set item focus on
ListView
is first item andScrollToPosition
isScrollToPosition.Start
(use animated = true
if you want to see the scroll happen)
Create a flag: ScrollToTop = true
use at layout .xaml that handler change Scroll of ListView.
You try it:
var firstItem = ((IEnumerable<object>)extListView.ItemsSource)?.FirstOrDefault();
if (firstItem != null)
extListView.ScrollTo(firstItem, ScrollToPosition.Start, false);
Hope it can help you!
add a comment |
up vote
0
down vote
accepted
This is my idea:
- Use method
ScrollTo
of ClassListView
(ScrollTo). - Set item focus on
ListView
is first item andScrollToPosition
isScrollToPosition.Start
(use animated = true
if you want to see the scroll happen)
Create a flag: ScrollToTop = true
use at layout .xaml that handler change Scroll of ListView.
You try it:
var firstItem = ((IEnumerable<object>)extListView.ItemsSource)?.FirstOrDefault();
if (firstItem != null)
extListView.ScrollTo(firstItem, ScrollToPosition.Start, false);
Hope it can help you!
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
This is my idea:
- Use method
ScrollTo
of ClassListView
(ScrollTo). - Set item focus on
ListView
is first item andScrollToPosition
isScrollToPosition.Start
(use animated = true
if you want to see the scroll happen)
Create a flag: ScrollToTop = true
use at layout .xaml that handler change Scroll of ListView.
You try it:
var firstItem = ((IEnumerable<object>)extListView.ItemsSource)?.FirstOrDefault();
if (firstItem != null)
extListView.ScrollTo(firstItem, ScrollToPosition.Start, false);
Hope it can help you!
This is my idea:
- Use method
ScrollTo
of ClassListView
(ScrollTo). - Set item focus on
ListView
is first item andScrollToPosition
isScrollToPosition.Start
(use animated = true
if you want to see the scroll happen)
Create a flag: ScrollToTop = true
use at layout .xaml that handler change Scroll of ListView.
You try it:
var firstItem = ((IEnumerable<object>)extListView.ItemsSource)?.FirstOrDefault();
if (firstItem != null)
extListView.ScrollTo(firstItem, ScrollToPosition.Start, false);
Hope it can help you!
edited Nov 22 at 15:57
answered Nov 22 at 15:45
user10666363
add a comment |
add a comment |
up vote
1
down vote
I use the following code to scroll my ListView classes to a specific position.
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, y), animated);
When scrolling, X normally will not change, but Y is the value you would like changed. Using that code scrolling to the top would be like this:
// You can send true for the animate property whether or not you want to see the scroll happen
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, 0), true);
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
add a comment |
up vote
1
down vote
I use the following code to scroll my ListView classes to a specific position.
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, y), animated);
When scrolling, X normally will not change, but Y is the value you would like changed. Using that code scrolling to the top would be like this:
// You can send true for the animate property whether or not you want to see the scroll happen
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, 0), true);
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
add a comment |
up vote
1
down vote
up vote
1
down vote
I use the following code to scroll my ListView classes to a specific position.
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, y), animated);
When scrolling, X normally will not change, but Y is the value you would like changed. Using that code scrolling to the top would be like this:
// You can send true for the animate property whether or not you want to see the scroll happen
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, 0), true);
I use the following code to scroll my ListView classes to a specific position.
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, y), animated);
When scrolling, X normally will not change, but Y is the value you would like changed. Using that code scrolling to the top would be like this:
// You can send true for the animate property whether or not you want to see the scroll happen
Control.SetContentOffset(new CGPoint(Control.ContentOffset.X, 0), true);
answered Nov 20 at 15:19
TaylorD
32016
32016
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
add a comment |
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
iOS somtimes can set to top on ListView. But first display of it can't set to top. @TaylorD
– Huu Bao Nguyen
Nov 21 at 2:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395591%2fcant-scroll-listview-to-top-on-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I tested your code without using ScrollToTopDelegate and it works well. The listView scroll to top when I call
ScrollToTop
function. Could you please provide more information to reproduce your problem?– Jack Hua - MSFT
Nov 21 at 3:19