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 7541923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:01:20+00:00 2026-05-30T08:01:20+00:00

I would like to create an implicit DataTemplate that works on an array or

  • 0

I would like to create an implicit DataTemplate that works on an array or IEnumerable of my class. This way I have a template that describes how to render a bunch of items instead of just one. I want to do this so I can, among other things, show the results in a tooltip. eg

<TextBlock Text="{Binding Path=CustomerName}" ToolTip="{Binding Path=Invoices}">

The tooltip should see that Invoices is a bunch of items and use the appropriate data template. The template would look something like this:

<DataTemplate DataType="{x:Type Customer[]}">
    <ListBox "ItemsSource={Binding}">
     etc

That didn’t work so I tried the example from this post x:Type and arrays–how? which involves creating a custom markup extension. This works if you specify the key but not for an implicit template

So then I tried making my own custom markup extension inheriting from TypeExtension like below but I get an error that says “A key for a dictionary cannot be of type ‘System.Windows.Controls.StackPanel’. Only String, TypeExtension, and StaticExtension are supported.” This is a really weird error as it is taking the content of the datatemplate as the key?? If I specify a key then it works fine but that largely defeats the purpose.

[MarkupExtensionReturnType(typeof(Type)), TypeForwardedFrom("PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class ArrayTypeExtension
    : TypeExtension
{
    public ArrayTypeExtension() : base() { }

    public ArrayTypeExtension(Type type) : base(type)
    {
    }

    public ArrayTypeExtension(string value) : base(value)
    {
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        Type val = base.ProvideValue(serviceProvider) as Type;
        return val == null ? null : val.MakeArrayType();
    }
}
  • 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-30T08:01:22+00:00Added an answer on May 30, 2026 at 8:01 am

    As noted in the question you linked to {x:Type ns:TypeName[]} works. It may screw over the designer but at runtime it should be fine.

    To avoid designer errors the template can be moved to App.xaml or a resource dictionary (or of course just don’t use the designer at all).

    (The error mentioning the control inside the template sounds like a bug in the code generator or compiler, sadly i doubt that there is much you can do about that one.)

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

Sidebar

Related Questions

I have a SQL Server Stored Procedure that looks like this: CREATE PROCEDURE [dbo].[my_stored_procedure]
I have a table that simplified looks like this: create table Test ( ValidFrom
I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I would like to create a stored procedure in MySQL that took a list
I would like to create events for certain resources that are used across various
I've got this code that works: def testTypeSpecialization: String = { class Foo[T] def
I would like to create a macro as such: <macrodef name=testing> <element name=test implicit=yes/>
i would like create a menu with kdialog like this kdialog --menu choose your
Good afternoon, I would like create a application that can can create folders and

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.