I am working in WPF and I need to set the Text and ToolTip of a Header of a HeaderedContentControl. So what I am trying to do is to create a template as below:
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;
But when I run the program the header is displayed empty. What am I doing wrong?
Hope someone can help, Thank you in advance
Have no idea why do you use template in a such way. Why not just set header property with the text block?
Moreover, it is even better idea to define all that in XAML: