Hi,I'm trying to do a basic binding for ComboBoxField but it appears to work differently than the standard ComboBox.
Given the following markup
<Window ... DataContext="{Binding RelativeSource={RelativeSource Self}}"/>
<StackPanel> <igDP:XamDataGrid DataSource="{Binding SectorAllocations}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:ComboBoxField Label="SectorID" Name="SectorID" ItemsSource="{Binding Sectors, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="Description" ValuePath="SectorID"></igDP:ComboBoxField> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <ListView ItemsSource="{Binding SectorAllocations}"> <ListView.View> <GridView> <GridViewColumn Header="SectorID"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox SelectedValue="{Binding SectorID}" ItemsSource="{Binding Sectors, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="Description" SelectedValuePath="SectorID"></ComboBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView></StackPanel>
and this codebehind
public partial class MainWindow : Window{ public SectorEntity[] Sectors { get; } = { new() { SectorID = 1, Description = "Item 1" }, new() { SectorID = 2, Description = "Item 2" } }; public SectorAllocation[] SectorAllocations { get; } = { new() { SectorID = 1, AllocationPercent = 0.5M}, new() { SectorID = 2, AllocationPercent = 0.7M}, }; public MainWindow() { InitializeComponent(); }}public class SectorEntity{ public int SectorID { get; set; } public string Description { get; set; }}public class SectorAllocation{ private int _sectorId; public int SectorID { get => _sectorId; set { _sectorId = value; Debug.WriteLine($"SectorID = {value}"); } } public decimal AllocationPercent { get; set; }}
The ComboBoxField does not seem to respect the DisplayMemberPath, nor does it present any items from the ItemsSource in the dropdown. There's something different about the way ComboBoxField is handling these compared to the standard ComboBox but I'm not sure what it is.
Little help?
Cheers,MattIGItemsSourceRepro.zip
Hello Matthew,
Thank you for posting to Infragistics Community!
I have been looking into your question and I believe the FieldBinding markup extension is what you are looking for. It would allow to directly bind to a property of the ViewModel. More information about it can be found here.
Additionally, I am attaching a modified version of your sample demonstrating the ComboBoxField correctly bound. Please, check it out on your side and let me know if you need any further assistance on the matter.
Best regards, Bozhidara Pachilova Associate Software Developer
8037.IGItemsSourceReproModified.zip
Ah, thank you very much! I hadn't come across FieldBinding before!
Hi Matthew,
I am glad the suggestion is helpful. Thank you for using Infragistics components!
Best regards, Bozhidara Pachilova