WPF Image Tooltip

2019-02-13 20:35发布

I have a tooltip on an image inside of a listbox. The tooltip is setup as follows:

<Image Grid.Column="0" Source="{Binding PingRankImage}" 
        Width="16" Height="16"
        HorizontalAlignment="Center" VerticalAlignment="Center">
    <Image.ToolTip>
        <ToolTip Content="{Binding Ping, StringFormat='Ping: {0}ms'}"
                    ContentStringFormat="{}Ping: {0}ms}" />
    </Image.ToolTip>
</Image>

but the tooltip just displays the value and not the 'Ping: XXXms'

Any ideas?

1条回答
【Aperson】
2楼-- · 2019-02-13 21:19

You don't need extra {} prefix in ContentStringFormat. With ToolTip, also prefer using ContentStringFormat instead of StringFormat in binding.

Following works:

<Image.ToolTip>
    <ToolTip Content="{Binding}"
                ContentStringFormat="Ping: {0}ms" />
</Image.ToolTip>
查看更多
登录 后发表回答