我试图如下:

<tk:DataGridTextColumn 
    Header="Item" 
    Binding="{Binding Item.Title}" 
    ToolTipService.ToolTip="{Binding Item.Description}" />

我看不到任何工具的尖端。

任何想法?它甚至实施?

有帮助吗?

解决方案

这对我的作品:

<Style TargetType="{x:Type Custom:DataGridColumnHeader}">
   <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="ToolTip" Value="{Binding Column.(ToolTipService.ToolTip), RelativeSource={RelativeSource Self}}"/>
      </Trigger>
   </Style.Triggers>
</Style>

其他提示

pls,检查,如果代码下面将对你的工作,它应该显示提示列标题和细胞、细胞的提示要弯曲描述领域的数据的对象:

<DataGridTextColumn Width="SizeToCells"   
                    MinWidth="150" 
                    Binding="{Binding Name}">

    <DataGridTextColumn.Header>
        <TextBlock Text="Name" ToolTipService.ToolTip="Header ToolTip" />
    </DataGridTextColumn.Header>

    <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="ToolTip" Value="{Binding Description}" />
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>
    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

解决方案找到了这里: 5随机的问题与WPF数据表格

在DataGridTextColumn是不可见的。你必须设置在头部或内容的工具提示。

要设置一个工具提示在头部,改变标头给TextBlock:

<tk:DataGridTextColumn
  Binding="{Binding Item.Title}">
  <tk:DataGridTextColumn.Header>
    <TextBlock
      Text="Text" 
      ToolTipService.ToolTip="Tooltip for header" />
  </tk:DataGridTextColumn.Header>
</tk:DataGridTextColumn>

要设置一个工具提示在列内容,将其设置在样式:

<tk:DataGridTextColumn
  Binding="{Binding Item.Title}"
  Heading="Text">
  <tk:DataGridTextColumn.ElementStyle>
    <Style>
      <Setter Property="ToolTipService.ToolTip" Value="{Binding Item.Description}" />
    </Style>
  </tk:DataGridTextColumn.ElementStyle>
</tk:DataGridTextColumn>

您可能还需要设置EditingElementStyle

此外,如果你的列是DataGridTemplateColumn代替DataGridTextColumn,你可以做这样的:

<DataGridTemplateColumn x:Name="MyCheckBoxColumn" CellStyle="{StaticResource MyCellStyle}" >
    <DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="MyHeaderName" ToolTip="This is my column description" />
        </DataTemplate>
    </DataGridTemplateColumn.HeaderTemplate>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox ... />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

设置ToolTipService.ToolTip属性,标题样式:

<Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>

下面是我如何使用它,当我在DataGridCheckBoxColumn代替文本有图像。 XAML:

    <Window x:Class="MyProject.GUI.ListDialog"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:viewModel="clr-MyProject.GUI.ViewModels" 
            Title="{Binding Title}"  Height="350" Width="650"
            MinHeight="350" MinWidth="650"
            xmlns:res="clr-MyProject.GUI.Resources" Closing="Window_Closing" WindowStyle="ToolWindow">
    <Window.Resources>
            <BitmapImage x:Key="MyImageSource" UriSource="Resources/Images/SelectDeselect.png" />
           <Style x:Key="CheckBoxHeader"  TargetType="DataGridColumnHeader">
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                            <Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Image Width="15" Height="15" Source="{StaticResource MyImageSource}" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    </Window.Resources>

C#:

DataGridCheckBoxColumn checkColumn = new DataGridCheckBoxColumn();
checkColumn.HeaderStyle = new System.Windows.Style();
checkColumn.CanUserSort = checkColumn.CanUserResize = false;
checkColumn.Width = new DataGridLength(25);
checkColumn.HeaderStyle = (Style)Resources["CheckBoxHeader"];
checkColumn.CellStyle = (Style)Resources["CenterAlignedCellStyle"];
checkColumn.IsReadOnly = false;
dataGrid.Columns.Add(checkColumn);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top