Prevent empty tooltips at a wpf datagrid
        Posted  
        
            by 
                TheCalendarProgrammer
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by TheCalendarProgrammer
        
        
        
        Published on 2011-11-22T17:18:18Z
        Indexed on 
            2011/11/22
            17:50 UTC
        
        
        Read the original article
        Hit count: 449
        
I am working on a calendar program, which consists mainly of a WPF DataGrid. As there is not always enough space to display all the entries of a day (which is a DataGridCell), a tooltip with all the entries of the day shell appear at mouse over. This works so far with the code snippet shown below. And now the (little) problem: If there are no entries for a day, no tooltip shell pop up. With the code below an empty tooltip pops up.
<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>
The Databinding is made via
myCalDataGrid.Itemssource = _listOfDays; 
in code behind, where a 'Day' is the view model for a single calendar row.
© Stack Overflow or respective owner