小编The*_*mer的帖子

防止wpf数据网格中的空工具提示

我正在制作一个日历程序,主要由WPF组成DataGrid.由于没有足够的空间来显示一天中的所有条目(即a DataGridCell),因此鼠标悬停时会显示包含日期shell的所有条目的工具提示.到目前为止,这可以使用下面显示的代码片段.现在(小)问题:如果一天没有条目,则不会弹出工具提示shell.使用下面的代码,弹出一个空的工具提示.

<DataGridTemplateColumn x:Name="Entry" 
                        IsReadOnly="True">
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <Grid>
        <TextBlock Text="{Binding EntryText}"
                   Foreground="{Binding EntryForeground}"
                   FontWeight="{Binding EntryFontWeight}">
        </TextBlock>
        <TextBlock Text="{Binding RightAlignedText}"
                   Foreground="Gray"    
                   Background="Transparent">
          <TextBlock.ToolTip>
            <TextBlock Text="{Binding AllEntriesText}"/>
          </TextBlock.ToolTip>
        </TextBlock>
      </Grid>
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)

数据绑定是通过

myCalDataGrid.Itemssource = _listOfDays; 
Run Code Online (Sandbox Code Playgroud)

在后面的代码中,'Day'是单个日历行的视图模型.

wpf datagrid tooltip

7
推荐指数
1
解决办法
7167
查看次数

标签 统计

datagrid ×1

tooltip ×1

wpf ×1