如何风格WPF类似工具提示的语音泡?(How to style WPF tooltip like a

2019-06-26 05:13发布

我想塑造我的WPF工具提示如下图:

如何实现这一目标?

Answer 1:

使用此代码:

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

这是开始时,现在你必须发挥它...享受!



Answer 2:

你可以创建一个新的工具提示控件模板 。



文章来源: How to style WPF tooltip like a speech bubble?