Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
xamDataGrid column size to content with some limit
posted

Hello,

I need to enable automatic sizing to content for xamDataGrid columns (fields) till some limit. I set Width="Auto" in FieldSettings and it does resize automatically but I can't find proper way to introduce the limit to stop the automatic resize. I want to allow the user to resize the columns manually without limitations, so setting CellMaxWidth or LabelMaxWidth in FieldSettings is not an option for me. Are there any built in options or recommended approaches for that?

Thanks in advance.

Parents
  • 34510
    Offline posted

    Hello Vital,

    There are no built in options that you can enable that would allow this.  If you set the CellMaxWidth or the LabelMaxWidth then it will restrict both mouse and content resizing.  You'd have to restrict the width manually, maybe by handling the LabelPresenter's SizeChanged event and then checking to see if the new size is caused by the mouse or the content.  If it is caused by the content then you can check to see if it passed a certain point.  Passed this point you would restrict the width of the field.

    In order to determine if the column was resized by mouse or not you can use the Mouse.LeftButton static property. http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.leftbutton(v=vs.110).aspx

    I haven't tested this myself just yet, I'm just throwing out an idea that may work.  I'm working on a sample to see if this will work for your needs.

Reply Children