我想以编程方式覆盖Tooltip Template。 等效的xaml代码是:
<Style TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的尝试:
ToolTip tooltip = new ToolTip();
tooltip.Content = panel; // Panel with text.
var controlTemplate = new ControlTemplate(typeof(ToolTip));
tooltip.Template = controlTemplate;
// ............. -> ContentPresenter ??
答案 0 :(得分:1)
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;