UserControl or storyboard inside treeviewitem

4 posts, 0 answers
  1. Mitch
    Mitch avatar
    1 posts
    Member since:
    Apr 2009

    Posted 15 Jun 2010 Link to this post

    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 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}"  /> 
                        <Image Source="{Binding CurrentPresence, Converter={StaticResource PresenceConverter}}" Margin="0, 0, 5, 0"/> 
                        <TextBlock Text="{Binding ContactName}" Margin="0, 0, 0, 0" />               

    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>(); 

    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?


  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 18 Jun 2010 Link to this post

    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.

    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
  3. pat
    pat avatar
    14 posts
    Member since:
    Aug 2011

    Posted 18 Aug 2011 Link to this post

    This reply seems to exactly repeat the code in the question.  What was the fix?
  4. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 24 Aug 2011 Link to this post

    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?

    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 >>

Back to Top