Both Windows Forms and in the WPF XamGrid control, there is support for showing the tooltip of a cell if its value overflows the cell. I think this is done with the AllowToolTips property in the XamGrid.
Is there anyway in the XamDataGrid to implement this same behaviour so that if the value of a cell overflows it and is cut off that it automatically displays the tooltip of that cell when the user hovers over it? Is this something that could apply to the whole grid versus haveing to specify it for each column?
Hello Michael,
I am glad to hear you have this worked out. Thank you for following up with your solution, I am sure it will be useful to other community members as well.
If you need any further assistance on this, please don’t hesitate to ask.
Petar,
Thank you for taking the time to look into this. I had actually ended up going with a different solution that seems to work.
I created a base CellValuePresenter style with an EventSetter triggered on MouseEnter. Then in the event handler I compare the length of the FormattedText of the cvp contents with the width of the cvp. Then I set the ToolTip accodingly. It ends up looking like the following.
private void OnCellMouseEnter(object sender, MouseEventArgs e) { var cvp = (sender as CellValuePresenter); if (cvp == null || cvp.Value == null) return; var ft = new System.Windows.Media.FormattedText(cvp.Value.ToString(), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface(cvp.FontFamily.ToString()), cvp.FontSize, cvp.Foreground); cvp.ToolTip = ft.Width < cvp.ActualWidth - 7 ? null : cvp.Value.ToString(); }
I am just checking, if you require any further clarification on the matter.
I have been looking into your comment and was able to reproduce the behavior you described. This is actually expected since the auto-sizing uses the inner SimpleTextBlock’s auto stretched size to know, if there is need to resize and enabling the TextTrimming allows the SimpleTextBlock to shrink to a size the same as the XamTextEditor/CellValuePresenter and tricks the functionality of thinking there is no need to resize. I have been banging my head at this and came up with turning off the TextTrimming on double-clicking the LabelPresenter, auto-sizing and again turning on the TextTrimming. I have put this into a the sample for your reference (Grid_Overflow_ToolTips_modified.zip)
Please let me know, if you require any further assistance on the matter.
I was going to put this solution into place, but I noticed one unfortunate side effect of it.
With this solution, when the user double clicks the edge of the column header to automatically size the column to the width of the longest value, the column width only gets sized to the width of the header. It completely ignores the cell values.
Is there anyway to get the column re-size to work as well?
Thanks.