我正在做以下操作,将扩展器添加到我的组合框 -
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”而不是值。
我在很多网站都发现了相同的问题,但没有答案。
感谢任何形式的帮助。 感谢。