Hi there
I'm a bit stuck, finding a solution to our following use case. We have a list of items in a XamDataGrid and an item has a property, which determines what kind of editor should be used to input a value for a second property.So if item.TypeData is "string", then the editor for Item.Value should be a XamTextEditor, if item.TypeData is "num", then the editor should be a XamNumericEditor, item.TypeData is "list" then the editor should be a XamComboEditor with a matching style (for stuff like ItemSource, DisplayMemberPath, ValuePath), and so on.
We fill a property called 'EditorStyle' depending on the property "TypeData" with the correct style in our object and try to bind it with a CellBinding. But this is only working, when the EditorType is set on the Field. (So for the whole column, not only the cell.) But if we try to use a XamTextEditor, when the Field.EditorType is set to another type than XamTextEditor, this obviously is not working.
<igDP:Field Name="CodeValue" > <!--<igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" /> </igDP:Field.Settings>--> <igDP:Field.CellBindings> <igDP:CellBinding Property="IsReadOnly" Target="Editor" Binding="{Binding Path=DataItem.DisallowCodeValue}" /> <!--<igDP:CellBinding Property="ValueType" Target="CellValuePresenter" Binding="{Binding Path=DataItem.ValueType}" />--> <igDP:CellBinding Property="Style" Target="Editor" Binding="{Binding Path=DataItem.EditorStyle}" /> </igDP:Field.CellBindings> </igDP:Field>
Any idea how to achieve this?
Hello Andreas,
I have been investigating into the behavior you are looking to achieve in this case, and I don’t believe the CellBinding that you have provided is doing what you think it is in this case. More specifically, the one targeting the Editor’s Style. This is going to target the Style of the Editor that is in the cell already, not the EditorStyle of the Field, and these are handled differently. Unfortunately, there does not exist a way to target the EditorStyle of the Field and bind that to a different value per cell.
This is not to say that your requirement is not achievable, though. My best recommendation for you in this case is to use a TemplateField. There, you can define an EditTemplate and put all of the editors inside with a Visibility setting of Collapsed initially. The DataTemplate that you define has a Triggers collection that you can then bind to data item properties on, and then you can add Setters to make one of the editors that you add to the DataTemplate visible.
I am attaching a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
XDGDifferentEditorsPerCellDemo.zip
Hi AndrewThank you very much for your detailed answer and the sample. It works fine and i can adapt it to our solution.But i have a question about some improvements. On the XamComboEditor we use the properties "ValuePath" and "DisplayMemberPath" to translate a Listvalue from "x" to "x | LocalizedDescription". And if i use your sample as is, the XamDataGrid shows the values as "x" instead of "x | LocalizedDescription", because we only have that definded for the EditTemplate and the DisplayTemplate is empty. Only if the user clicks in the cell and starts the EditMode, he can se the correct list value. So i just defined the same DataTemplate in the DisplayTemplate property of the TemplateField and adjusted some little stuff. Now the XamDataGrid is showing the correct "translated" value description.But to dropdown the list of the XamComboEditor, the user have to click twice on the cell. First time to enter EditMode, second time to dropdown the list. While on the other column, where there is a "normal" XamComboEditor in the column, he only has to click once.I hope it's understandable, what i mean... But do you have any idea how to improve this too?Regards