我想創建一個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