Backgroundcolor of entire ToolTip

风格不统一 提交于 2019-12-07 06:15:46

问题


Does anyone know a simple XAML solution to change the entire background of a ToolTip?

I did the following:

<Image Height="16" Source="Images/Icons/Add2.png" Stretch="Fill" Width="16" Opacity="0.99" Grid.Column="0">
    <Image.ToolTip>
        <Grid Background="#000000">
             <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
             </Grid.RowDefinitions>
             <TextBlock Text="Header1" FontSize="15" Grid.Row="0"/>
             <TextBlock Text="Subitem" FontSize="12" Grid.Row="1"/>
         </Grid>
    </Image.ToolTip>
</Image>

But the result looks like that:

Any suggestions?


回答1:


The problem is that all you're really doing is setting the CONTENT of the tooltip, not the tooltip itself.

So you'll need to style the tooltip to make this happen. There are some ways to do it with resources as seen in this post:

WPF- Changing Tooltip background to Transparent

or you can change your code to wrap that grid with an explicit ToolTip and set its background property:

<Image.ToolTip>
    <ToolTip Background="Black">
        <Grid>
            ...
        </Grid>
    </ToolTip>
</Image.ToolTip>


来源:https://stackoverflow.com/questions/13807354/backgroundcolor-of-entire-tooltip

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