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

UserControl or storyboard inside treeviewitem

3 Answers 89 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mitch
Top achievements
Rank 1
Mitch asked on 15 Jun 2010, 11:20 PM
I need to be able to start and stop a usercontrol or storyboard background from code for a particular radtreeviewitem when I want to alert the user that something has happened for a contact.

I have a databound radtreeview for a contact list.

<!-- data template for the Contact object--> 
        <telerik:HierarchicalDataTemplate x:Name="ContactTemplate" telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}" > 
            <local:ContactBackgroundControl x:Name="ContactBlinker" > 
                <StackPanel x:Name="ContactContent" Orientation="Horizontal"
                    <telerikNavigation:RadContextMenu.ContextMenu> 
                        <telerikNavigation:RadContextMenu x:Name="ContactContextMenu" ItemClick="RadMenuItem_Click" Opened="ContactContextMenu_Opened"
                            <telerikNavigation:RadMenuItem Header="Send IM"  Tag="{Binding SIPURL}" /> 
                            <telerikNavigation:RadMenuItem Header="Start Livemeeting" Tag="{Binding SIPURL}"  /> 
                        </telerikNavigation:RadContextMenu> 
                    </telerikNavigation:RadContextMenu.ContextMenu> 
                    <Image Source="{Binding CurrentPresence, Converter={StaticResource PresenceConverter}}" Margin="0, 0, 5, 0"/> 
                    <TextBlock Text="{Binding ContactName}" Margin="0, 0, 0, 0" />               
                </StackPanel> 
            </local:ContactBackgroundControl> 
        </telerik:HierarchicalDataTemplate> 

Inside the datatemplate I have a usercontrol I have created (ContactBackgroundControl) which is just a stackpanel with a background that goes from transperent to a color and back again.

When I try the code below, I get an error "Reference is not a valid visual DependencyObject" refering to when I do the FindChildByType call searching for the type "ContactBackgroundControl". I have also tried the type "UserControl", but that results in the same exact error.

public void SetContactBlinking(string sipuri) 
        { 
            //iterate thorugh each group, and each groups contacts in the treeview 
            foreach (ContactGroup group in OCSContactsTreeView.Items) 
            { 
                int ContactIndex = 0
                foreach (Contacts_ contact in group.Contacts_) 
                {  
                    //if the contact matches the sent sipuri, get the treeview item and set blinking 
                    if(contact.SIPURL == sipuri) 
                    { 
                        RadTreeViewItem TVItem = (RadTreeViewItem)(OCSContactsTreeView.ItemContainerGenerator.ContainerFromIndex(ContactIndex));  
                        //get the instance of the contactbackgroundcontrol and start the storyboard 
                        ContactBackgroundControl Control = TVItem.Template.FindChildByType<ContactBackgroundControl>(); 
                        Control.BlinkContact.Begin();                   
                    } 
                     
                    ContactIndex++; 
                } 
 
            } 
        } 

Is there any way to get a reference to the particular usercontrol inside the radtreeview item so I can start or stop the usercontrol storyboard? Or is there some better method to pull off an effect like this?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 18 Jun 2010, 04:41 PM
Hi Mitch,

You can get the ContactBackgroundControl through the FindChildByType() method, like so:
ContactBackgroundControl Control = TVItem.FindChildByType<ContactBackgroundControl>();

Please give it a try and let me know if it works for you.

Greetings,
Tina Stancheva
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
pat
Top achievements
Rank 1
answered on 18 Aug 2011, 09:57 PM
This reply seems to exactly repeat the code in the question.  What was the fix?
0
Tina Stancheva
Telerik team
answered on 24 Aug 2011, 12:12 PM
Hi Pat,

Mitch was looking for his custom control in the RadTreeViewItem.Template:
ContactBackgroundControl Control = TVItem.Template.FindChildByType<ContactBackgroundControl>();
However, the Template property is not a visual DependancyObject and therefore the FindChildByType() method cannot be used with it.

My suggestion was to use the FindChildByType() method directly on the RadTreeViewItem:
ContactBackgroundControl Control = TVItem.FindChildByType<ContactBackgroundControl>();

Are you facing similar issues? If so, can you please elaborate on them as we might be able to provide you with a better solution?

Regards,
Tina Stancheva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
TreeView
Asked by
Mitch
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
pat
Top achievements
Rank 1
Share this question
or