Reputation: 7
I want to override Tooltip Template programmatically. The equivalent xaml code is:
<Style TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
My attempt:
ToolTip tooltip = new ToolTip();
tooltip.Content = panel; // Panel with text.
var controlTemplate = new ControlTemplate(typeof(ToolTip));
tooltip.Template = controlTemplate;
// ............. -> ContentPresenter ??
Upvotes: 0
Views: 555
Reputation: 9827
ToolTip tooltip = new ToolTip();
tooltip.Content = panel; // Panel with text.
var controlTemplate = new ControlTemplate(typeof(ToolTip));
controlTemplate.VisualTree = new FrameworkElementFactory(typeof(ContentPresenter));
tooltip.Template = controlTemplate;
Upvotes: 1