This is a migrated thread and some comments may be shown as answers.

ContainerFromIndex is always NULL

4 Answers 241 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 03 Dec 2012, 09:17 PM
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

4 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 04 Dec 2012, 01:48 PM
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.

0
Tracy
Top achievements
Rank 1
answered on 04 Dec 2012, 02:29 PM
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
0
Pavel R. Pavlov
Telerik team
answered on 07 Dec 2012, 11:29 AM
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.

0
Tracy
Top achievements
Rank 1
answered on 11 Dec 2012, 05:03 PM
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
Tags
TileView
Asked by
Tracy
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Tracy
Top achievements
Rank 1
Share this question
or