Hi,
Here's my setup:
And here's my problem:
Am I missing a setting? I would like to continue using XamComboEditor's default template if possible.
Hello,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post and I created a sample project for you where the functionality you want is achieved. Basically after changing the DataSource of the XamComboEditor I iterated trough the Records and make the Cell with the Editor to enter and exit edit mode and I handled the EditModeEnding event, so I can change the Editor’s Value to the updated one.
Feel free to write me if you have further questions.
Here's the source code:
MainWindow.xaml
<Window x:Class="XamGridTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igd="http://infragistics.com/DataPresenter" xmlns:Editors="http://infragistics.com/Editors" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ControlTemplate TargetType="{x:Type Editors:XamComboEditor}" x:Key="ComboEditorTemplate"> <ComboBox ItemsSource="{TemplateBinding ItemsSource}" SelectedItem="{TemplateBinding SelectedItem}" DisplayMemberPath="{TemplateBinding DisplayMemberPath}" /> </ControlTemplate> </Window.Resources> <DockPanel> <!-- Editor for item labels --> <ListBox DockPanel.Dock="Left" Width="200" x:Name="lstLabelEditor" ItemsSource="{Binding ItemCollection}"> <ListBox.ItemTemplate> <DataTemplate> <TextBox Text="{Binding ItemLabel, Mode=TwoWay}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <!-- Xam data binding --> <igd:XamDataGrid x:Name="xdgDataGrid" DataSource="{Binding Records}" FieldLayoutInitialized="OnFieldLayoutInitialized"> <igd:XamDataGrid.FieldLayoutSettings> <igd:FieldLayoutSettings AutoGenerateFields="False" /> </igd:XamDataGrid.FieldLayoutSettings> </igd:XamDataGrid> </DockPanel> </Window>
MainWindow.xaml.cs
using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; using System.Windows.Data; using Infragistics.Windows.DataPresenter; using Infragistics.Windows.DataPresenter.Events; using Infragistics.Windows.Editors; namespace XamGridTest { public partial class MainWindow { private readonly MainViewModel _mainViewModel = new MainViewModel(); public MainWindow() { InitializeComponent(); DataContext = _mainViewModel; } private void OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) { var layout = e.FieldLayout; layout.Fields.Clear(); // Field using XamComboEditor's default template var comboField1 = new UnboundField { DataType = typeof (ItemViewModel), Label="Default template", Binding = new Binding("RecordItem") {Mode = BindingMode.TwoWay} }; layout.Fields.Add(comboField1); comboField1.Settings.EditorType = typeof(XamComboEditor); Style style1 = new Style(typeof(XamComboEditor)); { style1.Setters.Add(new Setter(XamComboEditor.ItemsSourceProperty, _mainViewModel.ItemCollection)); style1.Setters.Add(new Setter(XamComboEditor.DisplayMemberPathProperty, "ItemLabel")); comboField1.Settings.EditorStyle = style1; } // Field using XamComboEditor with custom template var comboField2 = new UnboundField { DataType = typeof (ItemViewModel), Label = "Custom template", Binding = new Binding("RecordItem") {Mode = BindingMode.TwoWay} }; layout.Fields.Add(comboField2); comboField2.Settings.EditorType = typeof(XamComboEditor); Style style2 = new Style(typeof (XamComboEditor)); { style2.Setters.Add(new Setter(XamComboEditor.ItemsSourceProperty, _mainViewModel.ItemCollection)); style2.Setters.Add(new Setter(XamComboEditor.DisplayMemberPathProperty, "ItemLabel")); style2.Setters.Add(new Setter(TemplateProperty, FindResource("ComboEditorTemplate"))); comboField2.Settings.EditorStyle = style2; } } } // Main view model public class MainViewModel { private readonly ObservableCollection _itemCollection = new ObservableCollection { new ItemViewModel{ItemLabel="Default item 1"}, new ItemViewModel{ItemLabel="Default item 2"}, new ItemViewModel{ItemLabel="Default item 3"}, }; public ObservableCollection ItemCollection { get { return _itemCollection; } } private readonly ObservableCollection _records; public ObservableCollection Records { get { return _records; } } public MainViewModel() { _records = new ObservableCollection { new RecordViewModel{RecordItem = _itemCollection[0]}, new RecordViewModel{RecordItem = _itemCollection[1]}, new RecordViewModel{RecordItem = _itemCollection[2]}, new RecordViewModel{RecordItem = _itemCollection[0]}, new RecordViewModel{RecordItem = _itemCollection[1]}, new RecordViewModel{RecordItem = _itemCollection[2]}, }; } } // Record view model public class RecordViewModel : INotifyPropertyChanged { private ItemViewModel _recordValue; public ItemViewModel RecordItem { get { return _recordValue; } set { _recordValue = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("RecordItem")); } } public event PropertyChangedEventHandler PropertyChanged; } // Item view model public class ItemViewModel : INotifyPropertyChanged { private string _itemLabel; public string ItemLabel { get { return _itemLabel; } set { _itemLabel = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ItemLabel")); } } public event PropertyChangedEventHandler PropertyChanged; } }