I have a DataGridTextColumn
in a Silverlight 4 DataGrid
and I want to set a ToolTip value on the column that is different from the bound value.
I know I can do this with a templated column quite easily - but it adds a huge amount of extra XAML and makes it cumbersome to read and maintain.
This works, but is a lot of extra code - especially if ever need to change the template
<data:DataGridTemplateColumn Header="Name" Width="*">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextTrimming="WordEllipsis" Text="{Binding FullName}"
ToolTipService.ToolTip="{Binding Email}" Width="Auto" Margin="5" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
I'd like to find a nice way to do this with either a Style or inherited class. Like I said my main goal is to reduce bloat in the XAML for something so trivial as a tooltip in the best possible way.
There are a few similar stackoverflow questions with solutions like this and this, but they both show the same tooltip value as the contents of the cell (for instance when it overflows). While this is often what you want - I'm trying to show a different tooltip to the cell's contents.
I did find some sample code for an inherited class (scroll to end), which i tried to modify but got stuck becasue my XAML knowledge isn't up to par and I don't want to spend all night on this! This particular example appears like it works, but it looks like quite a hack and I think trying to modify it to work with two dependency properties is going to be an even bigger one.
PS. I would expect that a well written subclass would make it easy for me to bind other properties such as TextTrimming also.