我在 WPF 中工作,我需要设置HeaderedContentControl的标题的文本和工具提示。所以我想做的是创建一个模板,如下所示:
System.Windows.DataTemplate template = new System.Windows.DataTemplate();
template.DataType = typeof(HeaderedContentControl);
System.Windows.FrameworkElementFactory blockFactory = new System.Windows.FrameworkElementFactory(typeof(TextBlock));
blockFactory.SetValue(TextBlock.TextProperty, "The Header Text");
blockFactory.SetValue(TextBlock.ToolTipProperty, "The ToolTip");
template.VisualTree = blockFactory;
myHeaderedContentControl.HeaderTemplate = template;
但是当我运行程序时,标题显示为空。我究竟做错了什么?
希望有人可以帮助,提前谢谢