不懂 ComboBox 文字渲染

Don't understand ComboBox text rendering

我正在尝试用 Gtk 编写 c# 应用程序,它可以通过反射加载 类 并查看表单上的所有方法。我添加了一个 ComboBox 组件来显示和选择 类 可供选择。但是当我填充组合框项目时,它们呈现不正确,正如您在 screen

上看到的那样

标题重复次数与组合框中的项目一样多(如果项目数为 4,则重复 4 次)

为了填充组合框,我接下来做了:

            ListStore model = new ListStore(typeof(string), typeof(Type));
            

            foreach (var type in allImplementsOf)
            {
                var iter = model.AppendValues(type.Name, type);
                CellRendererText c = new CellRendererText();
                _classComboBox.PackStart(c, true);
                _classComboBox.AddAttribute(c, "text", 0);
            }
            
            _classComboBox.Model = model;

我该如何解决?
P.S。对不起我的英语。

A CellRendererComboBox 的层上工作,而不是在单个条目的层上。因此,您的 ComboBox 需要一个可以渲染每个条目的渲染器。每个条目文本被渲染 n 次的原因是您使用 n 渲染器,其中每个渲染器都应用于每个条目。如果您只是将渲染器移出循环,它应该可以工作:

ListStore model = new ListStore(typeof(string), typeof(Type));
        

foreach (var type in allImplementsOf)
{
    var iter = model.AppendValues(type.Name, type);
            
}
        
_classComboBox.Model = model;
CellRendererText c = new CellRendererText();
_classComboBox.PackStart(c, true);
_classComboBox.AddAttribute(c, "text", 0);