user1011394
user1011394

Reputation: 1666

Backgroundcolor of entire ToolTip

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:

Tooltip background color

Any suggestions?

Upvotes: 9

Views: 10272

Answers (3)

Kflexior
Kflexior

Reputation: 337

To set the tooltip background you can override the style of the tooltip for the parent control. Below is your code with added style.

<Image Height="16" Source="Images/Icons/Add2.png" Stretch="Fill" Width="16" Opacity="0.99" Grid.Column="0">
    <Image.Resources>
        <Style TargetType="ToolTip" BasedOn="{StaticResource {x:Type ToolTip}}">
            <Setter Property="Background" Value="#000000" />
        </Style>
    </Image.Resources>
    <Image.ToolTip>
        <Grid>
             <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>

Upvotes: 3

Maghalakshmi Saravana
Maghalakshmi Saravana

Reputation: 811

To change or Set the Background/Foreground color for the Tooltip in DataGrid in WPF

  1. Create the DataGrid as "Grid1" and add the DataGridTextColumn which contains the ToolTip with item.
  2. To change the Background colour for the ToolTip, add the Setter property in the DataGrid Resources
     <DataGrid x:Name="Grid1">
                 <DataGrid.Resources>
                   <Style TargetType="ToolTip">
                   <Setter Property="Background" Value="Black"></Setter>
                   <Setter Property="Foreground" Value="White"></Setter>
                   </Style>
                 </DataGrid.Resources>
             <DataGridTextColumn Header="ActionName" Binding={Binding ActionName}>
               <DataGridTextColumn.CellStyle>
                 <Setter Property="Control.ToolTip">
                   <Setter.Value>
                   <UniformGrid Columns="1">
                   <TextBlock Text="Action List" FontWeight="Bold"/>
                   <TextBlock Text="Cut"/>
                   <TextBlock Text="Copy"/>
                   <TextBlock Text="Delete"/>
                   </UniformGrid>
                  </Setter.Value>                                                
                 </Setter>             
               </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
         </DataGrid>

Upvotes: 0

Tim
Tim

Reputation: 15237

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>

Upvotes: 15

Related Questions