WPF Image Tooltip

不打扰是莪最后的温柔 提交于 2019-11-30 05:41:14

问题


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:


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>


来源:https://stackoverflow.com/questions/4847734/wpf-image-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!