1
votes

I have a DataGrid that has the ItemSource property binded to a propery from my model.and i want to have a combobox column in the grid binded also to a property form the same model, not inside the property object that is binded on ItemSource

<DataGrid ItemsSource="{Binding Path=Model.ObjectList}" AutoGenerateColumns="False" AllowDrop="False">
    <DataGrid.Columns>
    <DataGridTemplateColumn Header="Item No.">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="?????" SelectedValue="{Binding Path=ItemNumber}" SelectedValuePath="Id"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGrid>

The columns of the grid can have bindings only to properties that are inside an Object element from my ObjectList, Is there a way to bind a property from the parent model to a grid cell?

1

1 Answers

1
votes

You should use something like that :

{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path= DataContext.ItemSourcePropery}"

where ItemSourceProperty is the ObservableCollection which you want to bind to. Also if you are in a window, set type "Window" or whatever else.