我无法绑定WPF DataGridComboBoxColumn并设置初始值。我可以使用集合中的数据填充组合框,但我似乎无法设置初始值。
<DataGridComboBoxColumn Header="Target Account Number"
ItemsSource="{Binding Account.RawAccountNumber}"
SelectedValueBinding="{Binding Account.RawAccountNumber, Mode=TwoWay}"
DisplayMemberPath="RawAccountNumber"
SelectedValuePath="RawAccountNumber">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Accounts}"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Accounts}"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
我尝试更改ItemSource,但这会导致组合框变空。
我看过several SO posts但这些都没有给我带来答案。请有人帮我指点正确的方向吗?
UPDATE 我打算包含我的datagrid定义,显示Grid的ItemSource。
<DataGrid x:Name="dataGrid" DataGridCell.Selected="DataGrid_GotFocus" AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="10,51,0,0" VerticalAlignment="Top" Height="521" Width="862" ItemsSource="{Binding Transaction.Rows}">