ContainerFromIndex is always NULL

5 posts, 0 answers
  1. Tracy
    Tracy avatar
    29 posts
    Member since:
    Sep 2010

    Posted 03 Dec 2012 Link to this post

    Hi,

    In the following code snippet, ChartTiles is my RadTileView.  The ItemsSource is being set to my ObservableCollection of ChartViewModel.

    for (int i = 0; i < ChartTiles.Items.Count; i++)
    {
        object item = ChartTiles.Items[i];
        object container = ChartTiles.ItemContainerGenerator.ContainerFromIndex(i);
    }


    --item is always set to the proper ChartViewModel.
    --container is always NULL.

    Note -- ContainerFromItem(item) doesn't work either -- even if I cast item as a ChartViewModel.

    I need to be able to get the RadTileViewItem pertaining to the ChartViewModel because I need to set the MaximizedItem in code -- and according to some of the other threads that it what I need to do to accomplish this.

    Any help would be appreciated.

    Thanks,

    Tracy

  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 04 Dec 2012 Link to this post

    Hi Tracy,

    In order to get the ItemContainer you have to make sure that the item has been created before calling the
    ItemContainerGenerator.ContainerFromIndex(index) method. You can try to handle the Loaded event of the RadTileView control and place your logic inside the handler. Let me know if this approach works for you.

    Kind regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Tracy
    Tracy avatar
    29 posts
    Member since:
    Sep 2010

    Posted 04 Dec 2012 Link to this post

    My code snippet is being run in respond to a user want to reset the tile layout to the original layout, so the tiles have already been created and visible on the screen.

    The ItemContainerGenerator.Status is "ContainersGenerated", even though the container object returned is always NULL.

    Note -- I am running version 2011.3.1220.35 and CANNOT upgrade at this time.  If there is a work around to being able to set the MaximizedItem, I would gladly use that.

    Thanks,

    Tracy
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 07 Dec 2012 Link to this post

    Hello Tracy,

    I tried to reproduce your issue and it seems that the code works as expected. The ItemContainerGenerator.ContainerFromIndex(0) returns the first container when the items are generated. Please take a look at the attached project and let me know if I miss something.

    Also, as a work around for your second question you can try setting the MaximizedItem property and bind it to a property of your business data.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Tracy
    Tracy avatar
    29 posts
    Member since:
    Sep 2010

    Posted 11 Dec 2012 Link to this post

    It turns out my code is being run after a LoadLayout of a docking control which is an ancestor of the RadTileView.

    So, even though it says that the containers have been generated, they have actually been wiped out.
    I moved my code to the Loaded event and that fixes the problem.

    Tracy
Back to Top
UI for WPF is Visual Studio 2017 Ready