我想创建一个WPF工具提示,其中包含工具提示标题的标签,然后是包含更多详细文本的文本块。我创建了以下样式在资源字典:自定义WPF工具提示
<Style x:Key="AppToolTip"
TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<StackPanel>
<Label Content="{TemplateBinding Content}" FontWeight="Bold" Background="Blue" Foreground="White">
</Label>
<TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
</TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value></Setter>
</Style>
而且可以这种风格成功地应用到一个按钮,像这样并有提示出现头:
<Button.ToolTip>
<ToolTip Style="{DynamicResource PalletToolTip}">
<Binding Source="{x:Static ResStrings.New}"/>
</ToolTip>
</Button.ToolTip>
什么我卡上我如何从上面的用法中设置额外描述性文本的内容?显示工具提示标题时,我已经将数据绑定到Content属性。 任何读过Adam Nathan的WPF Unleashed书籍的人都会意识到,我使用他的示例工具提示XAML,但在他的情况下,他使用硬编码字符串作为标签和文本块的内容。我想创建更可重用的东西,因此希望使用数据绑定来实现相同的效果。
感谢肯特 - 我认为这看起来是最好的方法。 – Auburg