我一直在尝试使用可爱的Frameworkelementfactory创建ContentTemplate。使用Frameworkelementfactory不更新按钮内容
代码工作除了我不能设置按钮的内容。我已经尝试了很多东西,但我总是最终得到一个Button with Button = Button。
下面是生成contenttemplate的代码。为了您的更多信息,我正在使用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;
您好,我已阅读文档。它是一个TabItem,我设置了TabItem.Template,虽然在XAML中是Datatemplate类型,但我无法将其转换为Datatemplate。使用Controltemplate排序的作品!使用Xaml.load非常慢,也不能投射。是的,我已阅读它已被弃用。但为什么应该处理程序工作,但不是内容? – stackeroverflow 2012-02-15 16:52:14