WPF controls for collecting controls

I am trying to bind to a collection of controls that I generate dynamically:

<ItemsControl ItemsSource="{Binding CustomFields}">

And the code:

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

Getcustomfields simply generates some controls like ComboBox, text field, etc. Binding seems to work, but no controls appear in the window. Probably because I need a data item in the controls. My question is, what type of data do I need?

Thanks for any help

+3
source share
1 answer

The following property, similar to the same XAML that you use:

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

        return collection;
    }
}

, - ... , ?

+5

Source: https://habr.com/ru/post/1722927/


All Articles