WPF itemscontrol绑定到控件集合

WPF itemscontrol绑定到控件集合,wpf,data-binding,itemscontrol,Wpf,Data Binding,Itemscontrol,我正在尝试绑定到动态生成的控件集合: <ItemsControl ItemsSource="{Binding CustomFields}"> 以及守则: public ObservableCollection<Control> CustomFields { get { return GetCustomFields(); } } 公共ObservableCollectio

我正在尝试绑定到动态生成的控件集合:

<ItemsControl ItemsSource="{Binding CustomFields}">

以及守则:

    public ObservableCollection<Control> CustomFields
    {
        get
        {
            return GetCustomFields();
        }
    }
公共ObservableCollection自定义字段
{
得到
{
返回GetCustomFields();
}
}
Getcustomfields只生成一些控件,如ComboBox、textbox等。绑定似乎可以工作,但窗口没有显示我的任何控件。可能是因为itemscontrol中需要一个datatemplate。我的问题是我需要什么样的数据模板


感谢您的帮助

以下属性与您使用的XAML相同:

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

        return collection;
    }
}
公共可观测采集控件
{
得到
{
var collection=新的ObservableCollection();
添加(新按钮{Content=“Hello world”});
回收;
}
}

也许你的问题来自其他地方。。。您能给我们重现问题所需的代码吗?

谢谢,将ObservableCollection更改为UIElement类型而不是control有效。对不起,我还不能投票。