×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    WP8 LongListSelector - ScrollTo

    I wanted to check what possible solutions are known to counter a stupid behavior the new WP8 LongListSelector (LLS) has!

    Scenario:
    A page with a grouped LongListSelector that is being filled through an ObservableCollection on a ViewModel ( so MVVM is in effect - mvvm light )

    Problem:
    The WP8 LLS behavior that is different from WP7, is that it will jump to the last item added... so in my app, when the list is full, the user will see the 'bottom' of the list! Because it's the last added item.

    What I want:
    Of course because the LLS is grouped and sorted, I want the user to have a nice view from the top! In other words we need to reposition the LLS after it has been loaded, from the bottom to the top!

    Solution:
    My current solution ( and hence my question, because I want to know if someone has anything better ): when the loading is done in the ViewModel, I send a NotificationMessage with MVVM messaging to the View. In the View upon receiving this NotificationMessage I put following code:

    Code:
    this.LongListSelector.ScrollTo(this.LongListSelector.ItemsSource[0]);
    So why I hate this solution, because of the fact that I need to send an extra notification to the view!

  2. #2
    Registered User
    Join Date
    Jan 2013
    Location
    Timisoara, Romania
    Posts
    14

    Re: WP8 LongListSelector - ScrollTo

    Hi Depechie,

    I'm a little bit confused, tell me if your project is for WP 7.1 or 8. Because if you use the LLS from toolkit in WP 8, it won't work properly.

    Anyway, if that isn't your problem, than I suggest you to take a look at mvvm concept, because I don't think you understood how it works. Take a look here:

    http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx
    https://channel9.msdn.com/Forums/Tec...-Windows-Phone
    Alex Manolache

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    548

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by ADU View Post
    I'm a little bit confused, tell me if your project is for WP 7.1 or 8. Because if you use the LLS from toolkit in WP 8, it won't work properly.
    The reason why LongListSelector is not in the WP Toolkit is because it's part of the native SDK in WP8 - and it should be used over ListBox in either case.

    Quote Originally Posted by Depechie View Post
    Solution:
    My current solution ( and hence my question, because I want to know if someone has anything better ): when the loading is done in the ViewModel, I send a NotificationMessage with MVVM messaging to the View. In the View upon receiving this NotificationMessage I put following code:

    *CODE*

    So why I hate this solution, because of the fact that I need to send an extra notification to the view!
    If the solution works then I see no issue with it. When using MVVM people do get stuck on the idea that there doesn't need to be a) any hacks or b) any code in the code-being. Unfortunately, although Microsoft is fully aware of the MVVM pattern, they often make it difficult to implement so these kinds of workarounds are required.

    Other than that, I'd recommend using the Telerik controls if you can. They have more features than the built-in versions, and if you find a bug, they'll fix it *shock* ;-)

  4. #4
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by ADU View Post
    I'm a little bit confused, tell me if your project is for WP 7.1 or 8. Because if you use the LLS from toolkit in WP 8, it won't work properly.
    It's the 'native' LLS in the WP8 sdk...

    Quote Originally Posted by ADU View Post
    Anyway, if that isn't your problem, than I suggest you to take a look at mvvm concept, because I don't think you understood how it works.
    Euh... it's because I understand MVVM that I feel that my solution is a dirty hack! The LLS is MVVM bound to the ViewModel with PropertyChange events so that all the data and the loading is working correctly! But when the data is loaded the LLS will jump to the last item added > this is the behavior I'm trying to counter, with an MVVM solution. The only thing I've come up with is MVVM messaging to signal the View that the data loading in the ViewModel is done, only to reposition the LLS in the View.

  5. #5
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Well, I'm not a real purist when it comes to MVVM. But still, I find it a bit annoying that I need that extra one Messaging signal.
    And I was wondering if anyone else came up with another, maybe better, solution

    Concerning the telerik controls, I've had a licence for a year and never used it don't know why but my current apps never needed the 'extras' you get with them. But I must say, I never looked to 'hard' at all the possible features.

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    548

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by Depechie View Post
    Well, I'm not a real purist when it comes to MVVM. But still, I find it a bit annoying that I need that extra one Messaging signal.
    And I was wondering if anyone else came up with another, maybe better, solution

    Concerning the telerik controls, I've had a licence for a year and never used it don't know why but my current apps never needed the 'extras' you get with them. But I must say, I never looked to 'hard' at all the possible features.
    I do understand the issue - in my new app (which you've seen), I've had to directly call a method on a UI Control for similar reasons. Code in the code-behind isn't idea but if it's done correctly (ie. the VM messages the code-behind), then fine. It wouldn't be correct for the VM to have any actual reference or direct knowledge of that control.

  7. #7
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by theothernt View Post
    Code in the code-behind isn't idea but if it's done correctly (ie. the VM messages the code-behind)
    Well ok, we'll leave it to that it's what I also do when faced with such problems!

  8. #8
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: WP8 LongListSelector - ScrollTo

    FYI, this question was Featured. Glenn, I hope you enjoy your new toy!

  9. #9
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    I will for sure thanks!

  10. #10
    Registered User
    Join Date
    Jun 2013
    Posts
    4

    Re: WP8 LongListSelector - ScrollTo

    How about using behaviors? If you attach it to the long list selector, you wouldn't have to worry about messaging or anything - the behavior would know when the control is loaded and would call the ScrollTo on it.
    http://igrali.com

  11. #11
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    548

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by igrali View Post
    How about using behaviors? If you attach it to the long list selector, you wouldn't have to worry about messaging or anything - the behavior would know when the control is loaded and would call the ScrollTo on it.
    Good idea. Wouldn't the Behaviour trigger an event which would in turn called a Method or Command on the ViewModel? if so, you would be passing a reference from the Control to the VM. Just wondering if that's less "correct" or not?

  12. #12
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Well not sure if a behavior would be ok, but indeed maybe worth a shot!

  13. #13
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: WP8 LongListSelector - ScrollTo

    And of course it might be worth a wiki article and code snippet eventually if we agree a "right way" - or could include both options and let the community decide.

  14. #14
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Good idea... I'll try to get a test app up on my GitHub, so others can try it out and maybe add other solutions. So we can see what 'works' best.

  15. #15
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Well the repo is online! https://github.com/Depechie/LongListSelectorAdd

    If you run the project for the first time, the LongListSelector will be positioned at the last added item > at the bottom!
    When you uncomment the code in the code behind of the MainPage.xaml.cs and rerun the app, the LLS will be positioned at the top!

    Code to uncomment:

    //if(msg.Notification.Equals("ListReposition"))
    //this.LLS.ScrollTo(this.LLS.ItemsSource[0]);

Similar Threads

  1. LongListSelector with tap events to other pages
    By m.findlay93 in forum Windows Phone General
    Replies: 7
    Last Post: 2013-09-30, 19:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×