[英]WPF itemscontrol binding to collection of controls
我正在嘗試綁定到動態生成的控件集合:
<ItemsControl ItemsSource="{Binding CustomFields}">
和代碼:
public ObservableCollection<Control> CustomFields
{
get
{
return GetCustomFields();
}
}
Getcustomfields只生成一些控件,如ComboBox,文本框等。綁定似乎工作,但窗口不顯示我的任何控件。 可能是因為我需要在itemscontrol中使用datatemplate。 我的問題是我需要什么樣的數據模板?
謝謝你的幫助
以下屬性與您使用的XAML相同:
public ObservableCollection<UIElement> Controls
{
get
{
var collection = new ObservableCollection<UIElement>();
collection.Add(new Button { Content = "Hello world" });
return collection;
}
}
也許你的問題來自其他地方......你能給我們重現問題所需的代碼嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.