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

ParentTileView returns nothing

2 Answers 47 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Trude
Top achievements
Rank 2
Trude asked on 22 Jun 2011, 09:01 PM
I have this databound tileview declared (part of an itemscontrol):
<telerik:RadTileView  ItemContainerStyle="{StaticResource RadTileViewItemStyle1}"
                    IsSelectionEnabled="True" SelectionMode="Single" MaxRows="1" IsAnimationOptimized="True"
                    Loaded="TileView1_Loaded" PreviewTileSelectionChanged="TileView1_PreviewTileSelectionChanged"
                    MaximizeMode="Zero"/>

In the code behind I have:
Private Sub TileView1_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs)
    Dim _tv As RadTileView = sender
 
    _tv.ItemsSource = DirectCast(_tv.DataContext, main_data_tab).details_tab
    AddHandler _tv.ItemContainerGenerator.StatusChanged, AddressOf ItemContainerGenerator_StatusChanged
 
End Sub
 
Private Sub ItemContainerGenerator_StatusChanged(sender As Object, e As System.EventArgs)
    Dim _cg = TryCast(sender, Telerik.Windows.Controls.ItemContainerGenerator)
 
    If _cg IsNot Nothing And _cg.Status = Primitives.GeneratorStatus.ContainersGenerated Then
        Dim _tileview = DirectCast(_cg.ContainerFromIndex(0), RadTileViewItem).ParentTileView
        If _tv IsNot Nothing Then
            For Each _item In _tv.Items
                Dim _container As RadTileViewItem = _cg.ContainerFromItem(_item)
                If _container.Tag Is Nothing Then
                    AddHandler _container.MouseEnter, AddressOf RadTileViewItem_MouseEnter
                    _container.Tag = "Processed"
                End If
            Next
        End If
    End If
End Sub

So, when the tileview is loaded I set it's ItemsSource and subscribe to the ItemContainerGenerator.StatusChanged event. If I add an item to the ItemsSource the event fires and I need to find which tileview raised it (ParentTileView of ContainerFromIndex(0)). I do get a reference to the TileViewItem, but it's ParentTileView property is nothing. If I add a second item the ParentTileView is suddenly pointing to the correct tileview. Is this intentional? Is there another way to find which tileview raised the event?

2 Answers, 1 is accepted

Sort by
0
Accepted
Zarko
Telerik team
answered on 24 Jun 2011, 01:30 PM
Hello Jorn,
This is expected behavior because when the StatusChanged event is fired with ContainersGenerated status all containers are already generated, but most of the properties of the last added container are still not set. There are two things you can do - if the ParentTileView property is null, you can get the parent RadTileView with the ParentOfType<T>() method like this:
 
Dim firstContainer = DirectCast(cg.ContainerFromIndex(0), RadTileViewItem)
Dim tileview = firstContainer.ParentTileView
If tileview Is Nothing Then
    tileview = firstContainer.ParentOfType(Of RadTileView)()
End If
 
If tileview IsNot Nothing Then
    For Each item As Object In tileview.Items
        Dim container As RadTileViewItem = TryCast(cg.ContainerFromItem(item), RadTileViewItem)
        If container.Tag Is Nothing Then
            container.MouseEnter += Me.container_MouseEnter
            container.Tag = "Processed"
        End If
    Next
End If
Or use a dispatcher to wait until the properties are set:
Me.Dispatcher.BeginInvoke(New Action(Function()
Dim tileview = DirectCast(cg.ContainerFromIndex(0), RadTileViewItem).ParentTileView
If tileview IsNot Nothing Then
    For Each item As Object In tileview.Items
        Dim container As RadTileViewItem = TryCast(cg.ContainerFromItem(item), RadTileViewItem)
        If container.Tag Is Nothing Then
            container.MouseEnter += Me.container_MouseEnter
            container.Tag = "Processed"
        End If
    Next
End If
 
End Function))
If you have more questions feel free to ask.

Greetings,
Zarko
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
0
Trude
Top achievements
Rank 2
answered on 24 Jun 2011, 01:58 PM
First method works great! Thanks!
Tags
TileView
Asked by
Trude
Top achievements
Rank 2
Answers by
Zarko
Telerik team
Trude
Top achievements
Rank 2
Share this question
or