0

我正在执行以下操作以将扩展器添加到我的组合框-

           GroupStyle groupStyle = new GroupStyle();
           Style style = new Style(typeof(GroupItem));

           ControlTemplate controlTemplate = new ControlTemplate(typeof(GroupItem));

           FrameworkElementFactory expanderFactory = new FrameworkElementFactory(typeof(Expander));

           FrameworkElementFactory dockPanelFactory = new FrameworkElementFactory(typeof(DockPanel));

           FrameworkElementFactory textBlockNameFactory = new FrameworkElementFactory(typeof(TextBlock));
           textBlockNameFactory.SetBinding(TextBlock.TextProperty, new Binding("Name"));
           textBlockNameFactory.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);

           dockPanelFactory.AppendChild(textBlockNameFactory);

           expanderFactory.SetValue(Expander.HeaderProperty, dockPanelFactory);
           expanderFactory.SetValue(Expander.IsExpandedProperty, true);
           expanderFactory.AppendChild(new FrameworkElementFactory(typeof(ItemsPresenter)));

           controlTemplate.VisualTree = expanderFactory;
           style.Setters.Add(new Setter(GroupItem.MarginProperty, new Thickness(0, 0, 0, 5)));
           style.Setters.Add(new Setter(GroupItem.TemplateProperty, controlTemplate));

           groupStyle.ContainerStyle = style;

           this.comboBox.GroupStyle.Add(groupStyle);

问题:在组合框中的运行时,扩展器的标题文本以“System.Windows.FrameworkElementFactory”的形式出现,而不是值。

我在许多网站上发现了相同的问题,但没有答案。

任何形式的帮助表示赞赏。谢谢。

4

0 回答 0