如何自定义工具提示窗口以在WPF中具有箭头

时间:2020-05-29 21:39:47

标签: wpf xaml tooltip

如何自定义工具提示窗口以使角箭头如下所示(在WPF(xaml)中显示)。

enter image description here

我的代码如下所示

 <Image x:Name="imgInfoTab">
            <Image.ToolTip>
      <ToolTip Background="WhiteSmoke" HasDropShadow="True" 
       Cursor="Hand">
          <TextBlock Width="250" Height="250"                                                         
      TextWrapping="WrapWithOverflow"                                                                                                                             
       Cursor="Hand">                                                   
        </TextBlock>
        </ToolTip>
       </Image.ToolTip>
        </Image>

使用上面的代码看起来如下所示, enter image description here

1 个答案:

答案 0 :(得分:0)

尝试一下:

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="CornflowerBlue">
    <Grid.ToolTip>
        <ToolTip Placement="MousePoint" HorizontalOffset="50">
            <ToolTip.Template>
                <ControlTemplate TargetType="ToolTip">
                    <Grid>
                        <Path Fill="White" Data="M 0,10 L 40,10 50,0 60,10 100,10 100,60 0,60" />
                        <TextBlock Text="Hello World!" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Grid>
                </ControlTemplate>
            </ToolTip.Template>
        </ToolTip>
    </Grid.ToolTip>
</Grid>

enter image description here

如果要自动调整大小,则需要执行a bit more work,但这将使您入门。