Programatically determine current items, and be notified on change

5 posts, 1 answers
  1. Adam Petaccia
    Adam Petaccia avatar
    30 posts
    Member since:
    May 2010

    Posted 24 Aug 2010 Link to this post

    I have a RadCarousel (not RadCarouselPanel) which is sometimes updated from an external source, or via the mouse, etc. What I need to be able to do is be notified that RadCarousel (or its panel) is changing which items are in view, and discover them so that the rest of the UI may update its state accordingly.

    What events would I need to bind to in order to accomplish this?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 26 Aug 2010 Link to this post

    Hi Adam Petaccia,

    In order to trace a change of the elements in the RadCarousel, you may handle CollectionChanged event of the Items Property:

    this.MyCarousel.Items.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_Col lectionChanged);

    However, in order this mechanism to work, the data for the carousel should implement the INotifyPropertyChanged Interface.
    As for discovering the visible items and updating the UI accordingly, I would need more details in order to provide you with an appropriate solution. What exactly are your requirements and expectations for using such a functionality?

    All the best,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Adam Petaccia
    Adam Petaccia avatar
    30 posts
    Member since:
    May 2010

    Posted 26 Aug 2010 Link to this post

    I apologize for being ambiguous; to clarify I don't wish to know when a visible item changes, I wish to know when the set of visible items changes. I've implemented my own buttons for manipulating the RadCarousel, and I can use RadCarousel.FindCarouselPanel().LineLeft to move the selection left, but I don't know what item(s) has/have come into focus. Ideally, I'm looking for something that would allow me to write code like this:

    RadCarousel.VisibleItemsChanged += (sender, visibleItemsChangedArgs) =>
    {
      RadCarousel carousel = (RadCarousel)sender;
      //...
      foreach (MyObjectType myObject in visibleItemsChangedArgs.NewItems)
      {
      //... update other UI and save state
      }
    }
    From this code I would be able to loop through the objects which have come into view (either because the user scrolled, or adjusted the number of visible items).
  5. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Sep 2010 Link to this post

    Hello Adam Petaccia,

    You may try to use the property of the RadCarouselPanel - Children - which will provide all visible elements. 
    So, for example the RadCarouselPanel can be found by the FindCarouselPanel method and then its corresponding property Children:

    private void RadButton_Click_1(object sender, RoutedEventArgs e)
    {
        RadCarouselPanel panel = this.MyCarousel.FindCarouselPanel() as RadCarouselPanel;
        MessageBox.Show("The number of children is: " + panel.Children.Count);
    }

    I am sending you a sample project illustrating the proposed solution.

    All the best,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Adam Petaccia
    Adam Petaccia avatar
    30 posts
    Member since:
    May 2010

    Posted 17 Sep 2010 Link to this post

    Sorry for the late response, that solution is indeed exactly what I was looking for. I didn't know it would be as simple as looking at children! ( I had thought it would show everything that _could_ be displayed).
Back to Top
UI for WPF is Visual Studio 2017 Ready