×

Discussion Board

Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: WP8 LongListSelector - ScrollTo

    I sort of found another solution.
    I've created a class that inherits from LongListSelector (already had that lying around, it has bindable SelectedItem as well )

    Code:
    Loaded += (sender, args) =>
    {
        ((INotifyCollectionChanged)ItemsSource).CollectionChanged += (sender2, args2) =>
        {
            if(ItemsSource.Count > 0)
                ScrollTo(ItemsSource[0]);
        };
    };
    In the Loaded Event of the ExtendedLongListSelector I cast the ItemsSource to INotifyCollectionChanged and that way I can handle the CollectionChanged event. If any item is in the collection I jump to the first one in the list.

    By putting this in a separate control you can at least keep your app's code clean.

    Here's a gist of the complete class https://gist.github.com/NicoVermeir/7698567

  2. #17
    Regular Contributor
    Join Date
    Jun 2013
    Posts
    53

    Re: WP8 LongListSelector - ScrollTo

    Ha! Maybe you can add a 'second page' in my GitHub project? https://github.com/Depechie/LongListSelectorAdd so we can see all the possible solutions... I haven't added my Bindable SelectedItem solution in there because only wanted to show the position problem.

    Small Q though, won't this also be triggered when an item is 'removed' from the list? I think you don't want to user to look for his previous position than > scenario when you could do delete of item by context menu, I would like the list to stay at that position, no?

  3. #18
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: WP8 LongListSelector - ScrollTo

    to allow deletion you can just add a check for the event args

    Code:
    ((INotifyCollectionChanged)ItemsSource).CollectionChanged += (sender2, args2) =>
    {
        if(ItemsSource.Count > 0 &&  args2.NewItems != null)
            ScrollTo(ItemsSource[0]);
    };
    NewItems will be null when an item is deleted from the collection

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

    Re: WP8 LongListSelector - ScrollTo

    Ha, that is better

    Now only one other thing, if you look at the twitter app on wp8 they have a scenario where you can load extra tweets, the list does not reposition than either... that would also be nice. But maybe not needed in all cases!
    Last edited by Depechie; 2013-11-29 at 08:17.

  5. #20
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: WP8 LongListSelector - ScrollTo

    a twitter app adds new tweets at the top of a listbox if I'm not mistaken but I'm not sure how you can actually stop the entire list from scrolling

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

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by NicoVermeir View Post
    a twitter app adds new tweets at the top of a listbox if I'm not mistaken but I'm not sure how you can actually stop the entire list from scrolling
    The official Twitter app uses the Telerik RadControls, so it's actually built-in

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

    Re: WP8 LongListSelector - ScrollTo

    Nico, that is a very nice solution. We definitely need a wiki article for this now - and ideally a single place to point users to (perhaps just have buildable project in a wiki zip).

  8. #23
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by hamishwillee View Post
    Nico, that is a very nice solution. We definitely need a wiki article for this now - and ideally a single place to point users to (perhaps just have buildable project in a wiki zip).
    will get right on it I'll explain the entire ExtendedSelector in an article, it also tackles the no bindable selected item problem

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

    Re: WP8 LongListSelector - ScrollTo

    The GitHub project now has Nico his solution merged in...

  10. #25
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: WP8 LongListSelector - ScrollTo


  11. #26
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    964

    Re: WP8 LongListSelector - ScrollTo

    Just wanted to thank you guys for all the extra effort on this subject.

    The wiki article and the Github project are nice additions

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

    Re: WP8 LongListSelector - ScrollTo

    I agree with Joao - going all the way to wiki is excellent.

    Quote Originally Posted by NicoVermeir View Post
    Nico, I've given it a minor update and added comments. Would appreciate if you could check it is still OK after my changes.

    Regards
    H

  13. #28
    Registered User
    Join Date
    Jan 2014
    Posts
    2

    Re: WP8 LongListSelector - ScrollTo

    Sorry if this will probably look like a little bit "warmed over", but here is yet another possible workaround :

    1. Subclass LongListSelector (as NikoVermeir mentioned, you will probably have done this already to implement a SelectedItem Dependency Property)
    2. Create a new Dependency Property of type object named ScrollToItem or whatever
    3. In the propertyChangedCallback of this DP, make the LongListSelector scroll to the property's new value :
      Code:
      private static void OnScrollToChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          if (e.NewValue == null)
              return;
          (d as LongListSelector).ScrollTo(e.NewValue);
      }
    4. In the ViewModel, create a ScrollToItem property and assign it to whatever you want at the end of the loading code, typically :
      this.ScrollToItem = this.GroupedItems.FirstOrDefault();
    5. In the View's LongListSelector XAML definition, add a binding to this property :
      Code:
              <LongListSelectorExt 
                                       (...)
                                       ScrollToItem="{Binding ScrollToItem}"
                                       >
                  <LongListSelectorExt >
    6. Et voilà !


    The nice thing is that this property can be used to scroll to any item at any moment.
    If anyone is interested I can post a complete code somewhere...

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

    Re: WP8 LongListSelector - ScrollTo

    Thanks, looks like another interesting solution.
    Quote Originally Posted by olivierb View Post
    If anyone is interested I can post a complete code somewhere...
    Could it fit into this article? : Fixing_the_LongListSelector

  15. #30
    Registered User
    Join Date
    Jan 2014
    Posts
    2

    Re: WP8 LongListSelector - ScrollTo

    Quote Originally Posted by hamishwillee View Post
    Could it fit into this article? : Fixing_the_LongListSelector
    It could certainly fit into it.
    And yet, after having looked at the whole wiki article, I'm not sure that my solution does provide anything more that what's already there.
    Since I'm quite new to blog posting, I will leave it up to you.

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
  •  
×