我正在尝试绑定(bind)到我动态生成的控件集合:
<ItemsControl ItemsSource="{Binding CustomFields}">
还有代码:
public ObservableCollection<Control> CustomFields
{
get
{
return GetCustomFields();
}
}
Getcustomfields 只生成一些控件,如 ComboBox、文本框等。绑定(bind)似乎有效,但窗口不显示我的任何控件。可能是因为我需要项目控件中的数据模板。我的问题是我需要什么样的数据模板?
感谢您的帮助
最佳答案
以下属性与您使用的 XAML 相同:
public ObservableCollection<UIElement> Controls
{
get
{
var collection = new ObservableCollection<UIElement>();
collection.Add(new Button { Content = "Hello world" });
return collection;
}
}
也许您的问题来自其他地方...您能给我们重现问题所需的代码吗?
关于WPF itemscontrol 绑定(bind)到控件集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1738408/