我正在开发一个日历程序,主要由WPF DataGrid
组成。由于有时候没有足够的空间来显示一天中所有的条目(也就是DataGridCell
),当鼠标悬停时会出现一个包含该日所有条目的提示框。下面的代码片段可以实现这个功能。但是现在有一个小问题:如果某天没有条目,则不会弹出提示框。使用下面的代码会弹出一个空提示框。
<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>
数据绑定是通过
{{}}
实现的。myCalDataGrid.Itemssource = _listOfDays;
在代码后台,其中“Day”是单个日历行的视图模型。