【发布时间】:2012-02-15 15:13:23
【问题描述】:
我一直在尝试使用可爱的 Frameworkelementfactory 创建一个 ContentTemplate。
除了我无法设置 Button 的内容外,该代码有效。我尝试了很多东西,但我总是得到一个 Content= Button 的 Button。
这是生成内容模板的代码。为了您的进一步信息,我在 Tabcontrol Header Itemtemplate 中使用它...
干杯。
ControlTemplate ct = new ControlTemplate(typeof(TabItem));
FrameworkElementFactory spouter = new FrameworkElementFactory(typeof (DockPanel));
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.TextProperty, Name);
spouter.AppendChild(text);
FrameworkElementFactory mButtonPrev = new FrameworkElementFactory(typeof(Button));
mButtonPrev.SetValue(System.Windows.Controls.Button.ContentProperty, "x");
mButtonPrev.AddHandler(System.Windows.Controls.Button.ClickEvent, new RoutedEventHandler(CloseTab));
spouter.AppendChild(mButtonPrev);
ct.VisualTree = spouter;
return ct;
【问题讨论】: