我正在制作一个日历程序,主要由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'是单个日历行的视图模型.