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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:11:57+00:00 2026-05-23T08:11:57+00:00

Trying to do something like this… public class MiniObject { public bool Checked {

  • 0

Trying to do something like this…

public class MiniObject
{
    public bool Checked { get; set; }
    public String Caption { get; set; }

    public ICollection<MiniObject> Content { get; set;}
}


<Window.Resources>
    <local:MiniObject x:Key="RootItem" Caption="Item0" Checked="True">
        <local:MiniObject.Content>
            <local:MiniObject Caption="Item1" Checked="True">
            </local:MiniObject>
            <local:MiniObject Caption="Item2" Checked="True">
            </local:MiniObject>
        </local:MiniObject.Content>
    </local:MiniObject>
</Window.Resources>

This of course doesn’t work returning the error:

Object of type 'WorkflowTest.MiniObject' cannot be converted to type 'System.Collections.Generic.ICollection`1[WorkflowTest.MiniObject]'.

Is there a way to do this within WPF? If so do I need to change the shape of my objects at all or can I simply provide a specialized object that only WPF uses like…

<Window.Resources>
    <local:MiniObject x:Key="RootItem" Caption="Item0" Checked="True">
        <local:MiniObject.Content>
            <local:MiniObjectCollection>
                <local:MiniObject Caption="Item1" Checked="True">
                </local:MiniObject>
                <local:MiniObject Caption="Item2" Checked="True">
                </local:MiniObject>
            </local:MiniObjectCollection>
        </local:MiniObject.Content>
    </local:MiniObject>
</Window.Resources>
  • 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-23T08:11:57+00:00Added an answer on May 23, 2026 at 8:11 am

    You’re trying to use XAML’s implicit collection syntax. In order to do this, the property (Content, in this case) must be of a type that implements ICollection. Note: not ICollection, but a type that implements ICollection.

    You can’t just use an interface because the XamlReader needs to know what type of object to create. If you haven’t told it the type, how should it decide? By searching through all of the types available to your assembly, finding the ones that implement ICollection<MiniObject>, discarding the ones that don’t have a parameterless constructor, and then choosing one at random? No.

    When you define Content as List<MiniObject>, the XamlReader knows what type of object it should create. Since that’s a type that implements ICollection, it can use the implicit collection syntax. So it just creates the object and calls Add to add the child items, and if you stuck a child item in there that isn’t a MiniObject you’ll get a runtime error.

    You say that “I need to avoid using an actual implementation” in your Content property. In that case, you cannot use the implicit collection syntax. You will need to do what you do in your second example: explicitly define a type that implements ICollection<MiniObject>, and add a child element in your XAML to create it explicitly.

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

Sidebar

Related Questions

I've trying to achieve something like this: class Base { public: Base(string S) {
Something like this is what Im trying to achieve: public Attribute<?> getAttribute(Class<? extends Attribute>
I'm trying do something like this if ($(this).parent() == $('div.propdata')){ $(this).prepend('<a class=booknow2 sidelink href=../../availability/default.aspx><span>Book
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
So I am trying to accomplish something like this: SELECT * FROM table WHERE
I'm trying to do a domain lookup in vba with something like this: DLookup(island,
So, I'm trying to consume a webservice using something like this: $client = new
I'm trying something like this, but this example does not work. jsObj = {};
I'm trying something like this: [ServiceContract ( CallbackContract = typeof (CallbackContract_1), CallbackContract = typeof

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.