One of the requirements I have for the Datagrid is to allow the user to resize all the columns to there liking and beable to save off the widths and reapply them when to go back to the page at a later time.
I figure I can just look through all the Fields in the FieldLayout, and read off the width, but is there an easier way to extract that information and put it back ?
Thanks
DK
Hi,
one of the soulution for catching user width change may be using SizeChange method and checking some of the fields from SizeChangedEventArgs:
private void labelPresenter_SizeChanged(object sender, SizeChangedEventArgs e) { if (e.WidthChanged && e.PreviousSize.Width != 0) { LabelPresenter lb = (e.OriginalSource as LabelPresenter); double colWidth = lb.Field.LabelWidthResolved; } }
Thanks!
I also would like to save and re-apply column width when user changes it. Did any body found a proper solution to this? Any sample/suggestion would help.
Thanks,
ND
Hey Andrew,
I will take a look at what you suggested with the mouse and go from there.
Thanks For the quick response.
If you get a chance to test out what your suggesting, could you post up some example code?
Unfortunately there isn't an event specific to resizing right now so I submitted a suggestion for it (as well as one for including save/load of user customizations). The SizeChanged event is defined on FrameworkElement and has to do with when the render size has changed so it would fire even when the element is just being positioned. I haven't tested this out but perhaps for now you could assume that a SizeChanged that occurs while the Mouse.LeftButton is Pressed means that a size change via a user interaction has changed (perhaps also limited to when the Mouse.Captured is non-null and is the DP or one of its descendants to ignore the case where a column is resized/positioned when the form, etc. is resized).
What you posted make sense, pretty simple for me to apply the widths back in during a FieldLayoutInit event.
However, I would like to capture when the user changes the column widths, and update my local list of column widths.
I tried to use the SizeChangedEvent on the LabelPresenter and HeaderPresenter and a few other classes. But all these give me a SizeChanged event no matter how the column got resized.
Is there an event tied specficly to when the user resizes a column?
I want to capture it and go ahead and update my stored column widths.
Any recommendation on how I could do this ?