Is there a way to make the column headers of my data grid editable when a user double clicks the label? What I am trying to do is allow a user to create a customer header that will be more descriptive of the values in that column and bind part of the label to the value they added
I tried doing something like this with a page resource but that did not work:
<igDP:FieldSettings x:Key="Ems.Page.HeaderGroupFieldSettings" LabelTextAlignment="Center" CellContentAlignment="LabelOnly" CellClickAction="EnterEditModeIfAllowed" AllowEdit="True" AllowRecordFiltering="False" LabelClickAction="Nothing" />
I have attached a sample that lets you double click on the XamDataGrid column headers and edit their text. In the sample, I provided a ContentTemplate to the LabelPresenter which contained the text for the label along with a XamTextEditor which will be used to edit the text. I then bound the LabelPresenter.Field.Label property to the XamTextEditor's Value property and I also bound the LabelPresenter.Tag property to the IsInEditMode property. I also added an EventSetter to handle the MouseDoubleClick event. Inside the event handler I set the LabelPresenter.Tag property to true. This causes a DataTrigger to fire which shows the text editor and since the IsInEditMode is bound to the Tag property, it is placed into edit mode. Once you have completed editing of the text and press the Enter key, this exits edit mode on the editor which sets the Tag property to false. This then reverts the trigger so the editor is hidden.
Let me know if you have any questions.
Thanks for your response, this was exactly what I was looking for. I made a couple changes because I didn't need all the style stuff that came with your example and I needed to bind the labels value to my VM so I could store the changes in a DB but your example was awesome!
Is it possible to do this without code-behind? This behavior is exactly what I need, but I need it in an MVVM pattern with no code-behind.
Also, I was trying to get this to work in that sample project with a XamTreeGrid instead of the XamDataGrid & it exhibits some strange behavior. It builds & loads fine, & double clicking the header sends it into edit mode fine as well. But when you try to then edit the header, it only allows you one keystroke then it ends edit mode. Any chance to get this working with a XamTreeGrid? I'm actually fine with the code-behind at this point, but I really need it to work with a TreeGrid.
You can definitely do this outside of code-behind. Usually this just means moving the code-behind into a Behavior<T> or creating an attached property that would be responsible for running the logic. I'll update the sample to remove the code behind.
As for getting editable columns working in the XamTreeGrid, i'll update the sample to a tree grid and see if I can reproduce that issue you are running into. Not sure why it would immediately end edit mode after one keystroke. Very weird.
I'll try to have something for you before the end of today.