The new TemplateField class only seems to work on properties directly on the DataItem. However, I have a case where I want to combine several properties into one field. Previously I used an UnboundField and a custom ControlHostEditor as described elsewhere in this forum.
Do I still have to use ControlHostEditor for this scenario?
Can you suggest a way to do this without CellValuePresenterStyle or ControlHostEditor?
Hello,
Thank you for your post. I have been looking into it and I can suggest you see the sample in the Samples Browser under xamDataGrid / Editing & Selection / Template Fields section, where it is shown how to use TemplateField. Please let me know if this helps you or you have further questions on this matter. Looking forward for your reply.
Thank you Stefan for your very helpful reply. Let me provide you a little more information.
Here is a simplified example. We have a complex object property on the data being displayed in a XamDataGrid. We would like to show a field in the grid that is bound to a property on that complex object. Here is how we do it with UnboundField:
<igWPF:UnboundField Name="Description"
Binding="{Binding ExceptionMessageCodeInfo.Description}"
Label="{Binding Source={x:Static Resources:Label.Description}, Converter={StaticResource AllCapsConverter}}" />
I would like to use TemplateField to customize the presentation of this deep property but TemplateField does not support drilling into properties. I am asking if I am still dependent on the ControlHostEditor method or can I use TemplateField in this scenario?
This code snippet will not work because the property binding requires drilling down into a complex property on the DataItem.
<igWPF:TemplateField Width="250" Label="{Binding Source={x:Static Resources:Label.Type}, Converter={StaticResource AllCapsConverter}}"> <igWPF:TemplateField.DisplayTemplate> <DataTemplate> <TextBlock Text="{Binding ExceptionMessageCodeInfo.Description}" ToolTip="{Binding ExceptionMessageCodeInfo.HowToResolve}" /> </DataTemplate> </igWPF:TemplateField.DisplayTemplate> </igWPF:TemplateField>
I have been out of the office since your last reply. Are you saying that I can set the BindingType of a TemplateField to Unbound and set the AlternateBinding to a Binding expression that gets me the datacontext I need for my Template?
I modified the sample you sent to test the answer to my question and found that I can use AlternateBinding on the TemplateField to solve the problem of my original question. Thank you!
<Grid> <igDP:XamDataGrid DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="True"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field BindingType="Unbound" AlternateBinding="{Binding Address.Name}" Label="Street Name"/> <igDP:Field Name="Address" Visibility="Collapsed"/> <igDP:Field BindingType="Unbound" AlternateBinding="{Binding Address.Number}" Label="Street Number"/> <igDP:TemplateField Label="Template Field" AlternateBinding="{Binding Address}"> <igDP:TemplateField.DisplayTemplate> <DataTemplate> <TextBlock> <Run Text="{Binding Name}" /> <Run Text=" -- " /> <Run Text="{Binding Number}" /> </TextBlock> </DataTemplate> </igDP:TemplateField.DisplayTemplate> <igDP:TemplateField.EditTemplate> <DataTemplate> <igEditors:XamTextEditor Value="{Binding Name}" /> </DataTemplate> </igDP:TemplateField.EditTemplate> </igDP:TemplateField> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid>
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
I've used the sample I found here but have another issue with it: Editing an unbound TemplateField does not Trigger the control to add a new record. You Need to have at least one bound field so adding the new record gets triggered. Can you reproduce this behavior? Is there any way to fix it?
The behavior is expected and the thing you can do is to handle the XamDataGrid's EditModeEnding event and in the handler you can check id the edited cell is in the AddNewRecord. If it is you can force the new record to be added by calling the XamDataGrid's RecordManger's CommitAddRecord method. Here is a code snippet you can use:
private void XamDataGrid_EditModeEnding(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndingEventArgs e) { if (e.Cell.Record.IsAddRecord) { (sender as XamDataGrid).RecordManager.CommitAddRecord(); } }
Hope this helps you.