Hi Mike
I finally got time to try out your suggestion and unfotunately the “flicker” you mention when refreshing the grid to force it to sort is proving a problem. It is acting differently for different columns (perhaps based on the header text width or the column contents width) but I have tried a lot of variations in the Creation Filter (see code below) to try and move the sort indicator out of the way and remove it altogether but nothing seems to work – the problem remains that the grid seems to be trying to find somewhere to put the indicator.
Any ideas would be very welcome. I am having trouble attaching an image from my machine showing the effect of the flicker but basically it shows one column’s header text bouncing right, one bouncing slightly left and one column header increasing in height. In call cases I think it’s trying to make space wherever it can for the sort indicator even though it has been removed. Below is the code for my creation filter. Thanks in advance!
public class RemoveSortIndicatorCreationFilter : IUIElementCreationFilter
{
private int sortIndicatorWidth = 0;
private int sortIndicatorHeight = 0;
#region IUIElementCreationFilter Memberspublic bool BeforeCreateChildElements(UIElement parent)
{
if ((parent.Parent is HeaderUIElement) && (parent is TextUIElement)) // HeaderUIElement) // SortIndicatorUIElement)
{
HeaderUIElement headerElement = parent.Parent as HeaderUIElement;
// only play with the text element size if this column is sorted
if (headerElement.Header.Column.SortIndicator != SortIndicator.None)
{
// Expand the text element to take account of the missing indicator
foreach (UIElement element in parent.Parent.ChildElements)
{
TextUIElement descripElem = element as TextUIElement;if (descripElem != null)
{
Rectangle origRect = descripElem.RectInsideBorders;
descripElem.Rect = new Rectangle(
origRect.Left,
origRect.Top,
origRect.Width + this.sortIndicatorWidth,
origRect.Height
);
break;
}
}
}
}
else if (parent is SortIndicatorUIElement)
{
foreach (UIElement element in parent.Parent.ChildElements)
{
SortIndicatorUIElement descripElem = element as SortIndicatorUIElement;if (descripElem != null)
{
Rectangle origRect = descripElem.RectInsideBorders;
this.sortIndicatorWidth = origRect.Width;
this.sortIndicatorHeight = origRect.Height;
descripElem.Rect = new Rectangle(
origRect.Left,
origRect.Top,
0,
0
);
break;
}
}
// remove teh sort indicator element
parent.Parent.ChildElements.Remove(parent);
parent.Dispose();
}
// Return false so PositionChildElements will get called to do the default child element creation.
return false;
}
public void AfterCreateChildElements(UIElement parent)
{
// nothing to do in this method
}
#endregion
}