Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 685603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:56:21+00:00 2026-05-14T01:56:21+00:00

Is it possible and if so what is the best way to implement the

  • 0

Is it possible and if so what is the best way to implement the following hierarchical structure in a silverlight (4) TreeView control? (where Item and Group are classes which can exist in the tree).


Group
|
|-Item
|
|-Group
| |
| |-Item
| |
| |-Item
|
|-Item

The structure could of course be arbitrarily more complex than this, if needed.

HierarchicalDataTemplates appear to be the way to approach this, but I’m specifically having trouble understanding how I might apply the template to interpret the different classes correctly.

A similar question was asked for WPF, the answer for which made use of the TargetType property on the HierarchicalDataTemplate, but I am uncertain whether that property is available in the silverlight version since I don’t appear to have access to it in my environment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:56:21+00:00Added an answer on May 14, 2026 at 1:56 am

    For Silverlight, you might need to create a converter to help do this. For instance, a “target type data template selector” or similar.

    Though you could get more advanced, here is an example from the Silverlight unit test framework that allows you to provide instances of data templates for hard-coded types. A generalized version could probably be made in about 20 minutes.

    To use this, you’d provide instances of data templates – in your case though, you’d probably need to make them hierarchical.

    <local:DataTemplateSelector 
        x:Key="DetailsViewDataTemplate"
        DefaultDataTemplate="{StaticResource DefaultDataTemplate}"
        TestMethodTemplate="{StaticResource TestMethodDataTemplate}"
        TestClassTemplate="{StaticResource TestClassDataTemplate}"/>
    

    And here is the implementation:

    /// <summary>
    /// A specialized data template selector.
    /// </summary>
    public sealed class DataTemplateSelector : IValueConverter
    {
        /// <summary>
        /// Gets or sets the default data template.
        /// </summary>
        public DataTemplate DefaultDataTemplate { get; set; }
    
        /// <summary>
        /// Gets or sets the test method template.
        /// </summary>
        public DataTemplate TestMethodTemplate { get; set; }
    
        /// <summary>
        /// Gets or sets the test class template.
        /// </summary>
        public DataTemplate TestClassTemplate { get; set; }
    
        /// <summary>
        /// Initializes a new instance of the DataTemplateSelector type.
        /// </summary>
        public DataTemplateSelector()
        {
        }
    
        /// <summary>
        /// Convert a value to a data template.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">The target parameter.</param>
        /// <param name="parameter">ConverterParameter value.</param>
        /// <param name="culture">The culture parameter.</param>
        /// <returns>Returns the object.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                Type type = value.GetType();
    
                if (typeof(TestMethodData).TypeHandle == type.TypeHandle)
                {
                    return TestMethodTemplate;
                }
                else if (typeof(TestClassData).TypeHandle == type.TypeHandle)
                {
                    return TestClassTemplate;
                }
            }
    
            return DefaultDataTemplate;
        }
    
        /// <summary>
        /// No 2-way databinding support.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">The target parameter.</param>
        /// <param name="parameter">ConverterParameter value.</param>
        /// <param name="culture">The culture parameter.</param>
        /// <returns>Returns the object.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to implement group/batch execution within a single web services
I would like know what is the best possible way to implement transactions with
Possible Duplicate: Best css reset What is the best way to implement CSS reset?
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
Possible Duplicate: Best way to copy the entire contents of a directory in C#
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some
Possible Duplicate: Best way to stop SQL Injection in PHP I need to secure
Possible Duplicate: Best way to programmatically detect iPad/iPhone hardware For example I want my
What is the best possible way using jQuery to give height and width to
I want to call this WS http://www.webservicex.net/country.asmx?op=GetCountries What is the best possible way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.