8

有谁知道一个简单的 XAML 解决方案来改变整个背景ToolTip

我做了以下事情:

<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>

但结果看起来像这样:

工具提示背景颜色

有什么建议么?

4

3 回答 3

14

问题是您真正要做的只是设置工具提示的内容,而不是工具提示本身。

因此,您需要设置工具提示的样式以实现此目的。如本文所示,有一些方法可以使用资源:

WPF-将工具提示背景更改为透明

或者您可以更改代码以使用显式工具提示包装该网格并设置其背景属性:

<Image.ToolTip>
    <ToolTip Background="Black">
        <Grid>
            ...
        </Grid>
    </ToolTip>
</Image.ToolTip>
于 2012-12-10T19:07:36.733 回答
1

要设置工具提示背景,您可以覆盖父控件的工具提示样式。下面是您添加样式的代码。

<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>
于 2020-05-14T13:21:01.867 回答
0

在 WPF 中更改或设置 DataGrid 中工具提示的背景/前景色

  1. 将 DataGrid 创建为“Grid1”并添加包含 ToolTip 和项目的 DataGridTextColumn。
  2. 要更改工具提示的背景颜色,请在 DataGrid 资源中添加 Setter 属性
     <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>
于 2020-01-20T05:18:52.083 回答