Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2325
Binding Observable Collection to a field in xamDataGrid populated by another collection within the viewmodel.
posted

I have a xamDataGrid that is being populated by an observable collection.

<igDP:XamDataGrid Name="xamOutputGrid" DataSource="{Binding OutputCollection}">
<igDP:Field Name="ID" Label="ForeignDescription">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings>
                                    <igDP:FieldSettings.EditorStyle>
                                        <Style TargetType="{x:Type igED:XamComboEditor}">
                                            How do I bind the data here?
                                        </Style>
                                    </igDP:FieldSettings.EditorStyle>
                                </igDP:FieldSettings>
                            </igDP:Field.Settings>
                        </igDP:Field>

Within this collection there is a field that is a guid referencing another collection.  How do I add a combo field to the xamdatagrid that is bound to the collection?  Which is to say I want to have a dropdown field which is populated from an observable collection and have the selected value point back to the main collection being used to fill out the rest of the grid.
  • 6365
    Offline posted

    Hello,

    In order to bind a collection with items for the XamComboEditor control of a field, you should be able to do this by binding the respective collection from the DataContext (presumably this is your ViewModel) to the ItemsSource property of the XamComboEditor. Please note that in order to access the DataContext of the Window, you will have to set it as a RelativeSource of the binding.
     
    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                         <Setter Property="ItemsSource" 
                                         Value="{Binding Path=DataContext.ComboItems, RelativeSource={RelativeSource AncestorType=Window}}" />
    </Style>

    I have prepared a sample application where this behavior is implemented and both the DataSource of the grid and the ItemsSource of the combo editor are bound to collections inside the ViewModel class.

    If you require any further assistance on this matter, please do not hesitate to ask.

    XamDataGrid_comboPopulatingMVVM.zip