2012-07-12 88 views
17

我要塑造我的WPF工具提示如下圖:如何像氣泡一樣設計WPF工具提示?

enter image description here

如何實現這一目標?

+0

我遇到類似的問題,最近又傳出與製作兩個職位,我相信可以幫助:http://pmichaels.net/2016/04/01/tooltip-speech-bubbles/和http:// pmichaels.net/2016/04/08/creating-a-speech-bubble-with-rounded-corners/ – 2016-04-19 20:02:51

回答

42

使用此代碼:

<Window x:Class="WpfApplication2.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" 
    Height="480"> 

<Window.Resources> 

    <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip"> 
     <Setter Property="OverridesDefaultStyle" Value="true" /> 
     <Setter Property="HasDropShadow" Value="True" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ToolTip"> 
        <ed:Callout Name="Border" 
           Width="{TemplateBinding Width}" 
           Height="{TemplateBinding Height}" 
           MinWidth="100" 
           MinHeight="30" 
           Margin="0,0,0,50" 
           AnchorPoint="0,1.5" 
           Background="{StaticResource LightBrush}" 
           BorderBrush="{StaticResource SolidBorderBrush}" 
           BorderThickness="1" 
           CalloutStyle="RoundedRectangle" 
           Fill="#FFF4F4F5" 
           FontSize="14.667" 
           Stroke="Black"> 
         <ContentPresenter Margin="4" 
              HorizontalAlignment="Left" 
              VerticalAlignment="Top" /> 
        </ed:Callout> 

       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

</Window.Resources> 
<Grid> 
    <Button ToolTip="Hello" /> 
</Grid> 

這是開始時,現在你必須發揮它...享受!

enter image description here

+0

謝謝哈利。我還有一個問題:我應該爲xmlns添加一個程序集:ed =「http://schemas.microsoft.com/expression/2010/drawing」? – 2012-07-12 09:37:46

+7

是的,添加Microsoft.Expression.Drawing程序集。 – Harry 2012-07-12 09:46:27

+0

太棒了!輝煌的工作,絕對是一個投票 – 2012-08-02 19:04:55

0

你可以創建一個新的工具提示control template

+0

你能發表一個有效的樣本嗎?看到替代實現會很有趣。 – Tim 2013-10-11 10:27:23