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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:48:00+00:00 2026-05-15T09:48:00+00:00

I have a custom control Workspace that inherits from Control and within it is

  • 0

I have a custom control Workspace that inherits from Control and within it is a DependencyProperty that I need to contain a user-specified IEnumerable<IFoo> (I have also tried making it an non-generic IEnumerable).

Public Shared ReadOnly FoosProperty As DependencyProperty = DependencyProperty.Register("Foos", GetType(IEnumerable(Of IFoo)), GetType(Workspace), New FrameworkPropertyMetadata())
Public Property Foos() As IEnumerable(Of IFoo)
    Get
        Return CType(Me.GetValue(FoosProperty), IEnumerable(Of IFoo))
    End Get
    Set(ByVal value As IEnumerable(Of IFoo))
        Me.SetValue(FoosProperty, CType(value, IEnumerable(Of IFoo)))
    End Set
End Property

Everything works perfectly when I create and set an array of IFoo in code but when I try to add them in XAML I get errors. If I add a single IFoo I get the error

  1. “‘FooItem’ is not a valid value for property ‘Foos’.”

at run time. If I try to add multiple IFoo items I get three errors at compile time

  1. The object ‘Workspace’ already has a child and cannot add ‘FooItem’. ‘Workspace’ can accept only one child.
  2. Property ‘Foos’ does not support values of type ‘FooItem’.
  3. The property ‘Foos’ is set more than once.

I read the errors to mean that WPF isn’t converting the xaml to an array of items like it normally would. Here is how I’m trying to add the items in XAML

<Workspace>
    <Workspace.Foos>
        <FooItem />
        <FooItem />
    </Workspace.Foos>
</Workspace>

I have created similar DependencyProperties in the past and never had a problem so I’m guessing I’m missing something simple.

Thanks for any help!

  • 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-15T09:48:00+00:00Added an answer on May 15, 2026 at 9:48 am

    To be able to add multiple elements the collection property has to be IList or IDictionary. When it is IEnumerable XAML parser tries to assign first value to the property itself (instead of calling Add like with lists) and gets confused about consecutive items. This is the source of your errors.

    Also, if you want to populate collection from XAML, make sure that your list is instantiated and not null to begin with, since XAML will not instantiate a list for you, it’ll just call Add on it. So to avoid NullReferenceException, get rid of setter on your IList property and instantiate list from constructor.

    It doesn’t have to be dependency property:

    private readonly ObservableCollection<FooItem> _foos = new ObservableCollection<FooItem>();
    
    public ObservableCollection<FooItem> Foos
    {
        get { return _foos; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom control that inherits from WebControl and implements IValidator, but I
I have a custom control that shows a value obtained from the database (the
I have a custom user control that contains asp:ValidationSummary . It is placed on
I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have a custom control that I had created I need to host it
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a custom control that exposes a property. When I set it using
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)
The background is I have a custom control that is a asp:Menu that is
I have a custom user control with a textbox on it and I'd like

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.