2012-07-12 18 views
17

quiero formar mi información de herramientas de WPF como la siguiente imagen:¿Cómo se estilo WPF Tooltip como un globo de diálogo?

enter image description here

¿Cómo lograr esto?

+0

me encontré con un problema similar hace poco y produce dos puestos que creo que puede ayudar: http://pmichaels.net/2016/04/01/tooltip-speech-bubbles/ y http: // pmichaels.net/2016/04/08/creating-a-speech-bubble-with-rounded-corners/ –

Respuesta

42

utilizar este código:

<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> 

este es el principio, ahora usted tiene que jugar con él ... disfrutar!

enter image description here

+0

gracias harry. Tengo otra pregunta: ¿debo agregar un ensamblaje para xmlns: ed = "http://schemas.microsoft.com/expression/2010/drawing"? –

+7

Sí, agregue el ensamblado Microsoft.Expression.Drawing. – Harry

+0

¡Impresionante! Brillante trabajo, definitivamente un VOTE UP –

0

puede crear una nueva información sobre herramientas control template.

+0

¿Se puede publicar una muestra de trabajo? Sería interesante ver una implementación alternativa. – Tim