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

  • Home
  • SEARCH
  • 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 96539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:49:53+00:00 2026-05-10T23:49:53+00:00

Problem I’ve got a collection of IThing s and I’d like to create a

  • 0

Problem

I’ve got a collection of IThings and I’d like to create a HierarchicalDataTemplate for a TreeView. The straightforward DataType={x:Type local:IThing} of course doesn’t work, probably because the WPF creators didn’t want to handle the possible ambiguities.

Since this should handle IThings from different sources at the same time, referencing the implementing class is out of question.

Current solution

For now I’m using a ViewModel which proxies IThing through a concrete implementation:

public interface IThing {     string SomeString { get; }     ObservableCollection<IThing> SomeThings { get; }     // many more stuff }  public class IThingViewModel {      public IThing Thing { get; }      public IThingViewModel(IThing it) { this.Thing = it; } }  <!-- is never applied --> <HierarchicalDataTemplate DataType='{x:Type local:IThing}'>  <!-- is applied, but looks strange --> <HierarchicalDataTemplate     DataType='{x:Type local:IThingViewModel}'     ItemsSource='{Binding Thing.SomeThings}'>     <TextBox Text='{Binding Thing.SomeString}'/> </HierarchicalDataTemplate> 

Question

Is there a better (i.e. no proxy) way?

  • 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. 2026-05-10T23:49:54+00:00Added an answer on May 10, 2026 at 11:49 pm

    The reason for this is that the default template selector supports only concrete types, not interfaces. You need to create a custom DataTemplateSelector and apply it to the ItemTemplateSelector property of the TreeView. I can’t find the URL where I found an example of it, but hopefully with this info, you can Google it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
Problem I'm trying to build a minimal example where I create a many-to-many relationship
Problem: Get a date inside of a JSONP response that looks like 2012-11-11T04:27:25Z (which
Problem: I have a non-copyable object with two constructors. I need to create an
PRoblem: i'm trying to create (just for fun) a simple poker card (with a
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
Problem: I want to create a generic function which will return me strogly typed
Problem: Been struggling to get my code to load external shaders and it is
Problem: I've written State Machine for my android application. It is separate class, extension
Problem Given a boolean expression consisting of the symbols 0, 1, &, |, ^

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.