I am binding a dictionary (int, string) to a xamcombobox as follows
<igDP:UnboundField Width="70" ToolTip="Assigned Entity" Tag="EntityString" Label="Assigned Entity" BindingPath="EntityString" BindingMode="TwoWay"> <igDP:UnboundField.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource LegalEntityDropdownCellStyle}" EditorType="{x:Type igEditors:XamComboEditor}"/> </igDP:UnboundField.Settings> </igDP:UnboundField>
where the CellValuePresenterStyle is defined as
<Style x:Key="LegalEntityDropdownCellStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igEditors:XamComboEditor SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Path=DataContext.LegalEntityNames}" DisplayMemberPath="Value" ValuePath="Key"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
I find that the value of the items in the combobox is in format "[key, value]" so I bind the field to a similarly formatted string. At the moment, the selectedItem in the combo box is not set. Any idea how to achieve that?
Hello Vikram,
I have modified teh sample I sent you before, so now all the code is in separate classes. Please let me know if this heslp you or you need further assistance on this maatter.
Looking forward for you.
Hi Stefan,
Your solution still has the "SelectedItemChanged" code in the "App.xaml.cs" file. Is there anyway of doing this without having this event at all and notifying the ViewModel about the selected item change in the XamComboEditor?
As we are using the MVVM pattern, we are not supposed to have any code in the .cs page.
Please help..
Regards,
Vikram
I have modified the sample I sent you before, so now it has the functionality you want. Basically I moved the Style and the event handler for the XamComboEditor in App.xaml and App.xaml.cs files.
Hope this helps you.
Hi Stefan
Your sample works like a charm.
But I still have a problem. As we are using MVVM pattern, I dont want to have the "XCEselectedItemChanged" event in the xaml.cs file. Is there any way we can notify the "SelectedItemChanged" to the view model?
I am absolutely new to WPF and have no clue how to achieve this.
Any help is highly appreciated.
Hello,
I have modified the sample I sent you before, so now you can see that the Data is updated when the ComboBox’ SelectedItem changes.