Reputation: 5093
My DataGrid
is bound to an ObservableCollection<Entry>
.
public class Entry
{
public List<string> Types {get; set;} = new List<string>() {"Type1", "Type2"};
}
Since DataGrid.ItemsSource
is an Collection of Entry
I expect the DataContext
of a single DataGridRow
to be typeof(Entry
).
<DataGrid ItemsSource="{Binding Entries}">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Border Width="100">
<StackPanel>
<ComboBox ItemsSource="{Binding DataContext.Entries[0].Types, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
<ComboBox ItemsSource="{Binding Types}" />
</StackPanel>
</Border>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
</DataGrid>
The first Binding
is working - the second is not.
Still I get no BindingError
in the Output
-Window of Visual Studio.
I need to show the Types
for each Entry
so access via index is not working.
Upvotes: 0
Views: 40
Reputation: 169200
This should work:
<ComboBox ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}}" />
Upvotes: 1