Intorduction :
This Blog introduced the how to use tooltip on silverlight datagrid columns.
We can use tooltipservice on silverlight datagrid perticuler columns dynamically.
Explanation:
1.ToolTipService :
Namespace : System.Windows.Controls.ToolTipService
Represents a service that provides static methods to display a tooltip.
public static class ToolTipService
ToolTipService.Tootip :Gets or sets a tooltip to be attached to a control.
To display a tooltip for a control we must use the ToolTipService class.
Use the static SetToolTip and GetToolTip methods to set and get the tooltip for a control.
2. Example :On Datagrid loadingrow event we apply the tooltipservice on datagrid columns.
DataGridControl.LoadingRow += new EventHandler<DataGridRowEventArgs>(DataGridControl_LoadingRow);
void DataGridControl_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridRow row = e.Row;
(DataGridControl.Columns[2].GetCellContent(row) as TextBlock).SetValue(ToolTipService.ToolTipProperty, (row.DataContext as AccountsList).Registration);
(DataGridControl.Columns[3].GetCellContent(row) as TextBlock).SetValue(ToolTipService.ToolTipProperty, (row.DataContext as AccountsList).Number);
(DataGridControl.Columns[4].GetCellContent(row) as TextBlock).SetValue(ToolTipService.ToolTipProperty, (row.DataContext as AccountsList).Type);
}
3. On XAML :
<Border BorderThickness="3" BorderBrush="Black">
<StackPanel Background="LightGray">
<TextBlock Text="ToolTip Control" Margin="5" />
<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Width="150" Text="Hover over an item to see its ToolTip: "
Margin="5" VerticalAlignment="Center" />
<ListBox Width="100" x:Name="myListBox" ToolTipService.ToolTip="ToolTip"
ToolTipService.Placement="Right" >
<ListBox.Items>
<ListBoxItem Content="Left" ToolTipService.ToolTip="ToolTip to the left."
ToolTipService.Placement="Left" />
<ListBoxItem Content="Right" ToolTipService.ToolTip="ToolTip to the right."
ToolTipService.Placement="Right" />
<ListBoxItem Content="Top" ToolTipService.ToolTip="ToolTip at the top."
ToolTipService.Placement="Top" />
<ListBoxItem Content="Bottom" ToolTipService.ToolTip="ToolTip at the bottom."
ToolTipService.Placement="Bottom"/>
<ListBoxItem Content="Mouse" ToolTipService.ToolTip="ToolTip based on the mouse."
ToolTipService.Placement="Mouse"/>
</ListBox.Items>
</ListBox>
</StackPanel>
</StackPanel>
</Border>