How can I disallow column resizing within the grid and only allow it in the header? If that is not possible, the next best thing would be to prevent mouse cursor from changing to horizontal resizing cursor within the grid and only allow it in the header. This is because when moving cursor in the grid, it constantly changes from arrow to horizontal resizing cursor and back, which is very distracting to the user as it makes UI feel unstable.
Hello,
One way to suppress resizing from the cells is to disable field resizing (AllowResize = false) when you are over a CellValuePresenter. For example :
private void xdg_PreviewMouseMove(object sender, MouseEventArgs e)
{
LabelPresenter lp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(LabelPresenter), true) as LabelPresenter;
if (lp == null)
CellValuePresenter cvp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(CellValuePresenter), true) as CellValuePresenter;
if (cvp != null)
cvp.Field.Settings.AllowResize = false;
}
else
lp.Field.Settings.AllowResize = true;
This doesn't work if you move mouse from right to left across the cells. I'm guessing the resize control is on the right of each cell, so the cell only gets its resize flag updated if you move mouse from left to right. I modified your code so that the entire grid's resize flag is updated depending on the kind of cell under the mouse, and that seems to work very well.
http://pastie.org/1015794
This should be reopened.
The handling of PreviewMouse is a bad idea because it completely trashes the CPU when hovering over the grid. It locks up the GUI thread, manifesting in delays when trying to click a cell after hovering over the grid.
I also don't like this hack and created an suggestion on UserVoice: http://ideas.infragistics.com/forums/192363-wpf/suggestions/5173245-xamdatagrid-option-to-disable-resizing-fields-by-
Votes appreciated ;)