views:

195

answers:

1

Hi,

I'm trying to bind to a collection of controls I generate dynamically:

<ItemsControl ItemsSource="{Binding CustomFields}">

And the code:

    public ObservableCollection<Control> CustomFields
    {
        get
        {
            return GetCustomFields();
        }
    }

The Getcustomfields just generates some controls like a ComboBox, textbox etc. The binding seems to work, but the window doesn't show any of my controls. Probably because I need an datatemplate in the itemscontrol. My question is what kind of datatemplate do I need?

Thanks for any help

+1  A: 

The following property like with the same XAML as you use:

public ObservableCollection<UIElement> Controls
{
    get
    {
        var collection = new ObservableCollection<UIElement>();
        collection.Add(new Button { Content = "Hello world" });

        return collection;
    }
}

Maybe your problem comes from somewhere else... Can you give us the code needed to reproduce the problem ?

Jalfp
Thanks, the changing the ObservableCollection to the UIElement type instead of control works. I cannot vote yet sorry.
Elger