以下是我的DataGrid XAML:無法綁定DataGridTemplateColumn組合框編輯模板
<DataGrid Visibility="Visible" Margin="20" ItemContainerStyle="{x:Null}" OverridesDefaultStyle="False" CellStyle="{x:Null}" Style="{x:Null}" RowStyle="{x:Null}" ColumnHeaderStyle="{x:Null}" Foreground="Black" CanUserAddRows="True" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Path=MovieList}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Title, Mode=TwoWay}" CanUserResize="True" MaxWidth="450" CanUserSort="True" Header="Title" Width="200" />
<DataGridTemplateColumn Width="130" Header="Type">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Type}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Width="120" ItemsSource="{Binding Path=GenreList}" DisplayMemberPath="Name" SelectedValuePath="ID" Height="Auto" HorizontalAlignment="Center" Name="comboBox1" VerticalAlignment="Top" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
的單元格編輯模板具有其綁定到一個觀察集合組合框「GenreList」。該集合在ViewModel中初始化。什麼可能是ComboBox未被填充的原因?
是GenreList在視圖模型的'DataGrid'或視圖模型的'DataGridRow '?只是猜測,但嘗試'ItemsSource =「{Binding RelativeSource = {RelativeSource AncestorType = {x:Type DataGrid}},Path = DataContext.GenreList}' – 2012-07-05 19:29:47