3

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

<ItemsControl ItemsSource="{Binding CustomFields}">

和代码:

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

Getcustomfields 只生成一些控件,如组合框、文本框等。绑定似乎有效,但窗口不显示我的任何控件。可能是因为我需要项目控件中的数据模板。我的问题是我需要什么样的数据模板?

谢谢你的帮助

4

1 回答 1

5

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

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

        return collection;
    }
}

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

于 2009-11-15T18:59:00.803 回答