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 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 Language: C# 2.0 or later I would like to register context handlers to
Problem is like this: Suppose there are records in dataTable with FruitType as A
?Problem is pretty simple, I extend Button to create ImageButton, and I extend ButtonSkin
Problem: Find people whose birthdays are tomorrow (table a), who havent got a record
Problem is like this: I have two winapi application's. There is only one way
Problem: I have a GROUP_CONCAT query that is working as intended, except I'd like
Problem I have a Silverlight 5 application using the treeview from the SDK. Now
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
Problem: I have an address field from an Access database which has been converted
Problem: I have two spreadsheets that each serve different purposes but contain one particular

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.