如何像气泡一样设置 WPF 工具提示的样式? [英] How to style WPF tooltip like a speech bubble?

查看:27
本文介绍了如何像气泡一样设置 WPF 工具提示的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像下图一样塑造我的 WPF 工具提示:

I want to shape my WPF tooltip like the image below:

我如何实现这一目标?

推荐答案

使用此代码:

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

这是开始,现在您必须玩它……享受吧!

this is the begining, now you have to play with it... enjoy!

这篇关于如何像气泡一样设置 WPF 工具提示的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆