I ended up doing this using a value converter for getting the tool tip:
using System;
using System.Data;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
namespace PreQuant
{
public class CellToolTipConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
throw new ArgumentNullException("values");
if (values.Length != 2)
throw new InvalidOperationException("Incorrect number of values passed to CellToolTipConverter");
DataRowView rowView = values[0] as DataRowView;
if (rowView == null)
throw new InvalidOperationException("Incorrect type of first (DataRowView) value passed to CellToolTipConverter");
DataRow row = rowView.Row;
if (row == null)
throw new InvalidOperationException("DataRow must not be null");
DataGridCell cell = values[1] as DataGridCell;
if (cell == null)
throw new InvalidOperationException("Incorrect type of second (DataGridCell) value passed to CellToolTipConverter");
DataGridColumn column = cell.Column;
if (column == null)
throw new InvalidOperationException("DataGridColumn must not be null");
string toolTip = null;
CellViewModel vm = row[column.SortMemberPath] as CellViewModel;
toolTip = vm.Information;
return toolTip;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}
And then got the
DataRowView
and
DataGridCell
values in the XAML as:
<Style x:Key="CellStyle"
TargetType="{x:Type DataGridCell}">
<Setter Property="ToolTip">
<Setter.Value>
<MultiBinding Converter="{StaticResource CellToolTip}">
<Binding />
<Binding RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
I assigned the
CellStyle
to the appropriate columns in the .xaml.cs code-behind.