Я пытаюсь использовать элемент управления DataGrid WPFToolkit (и C# /. Net 3.5) для отображения ComboBox на запись. С ниже коде на ComboBoxes появляются, но их выпадающие списки не содержат элементов:Binding DataGridComboBoxColumn ItemsSource to RelativeSource FindAncestor не работает
<wpftkit:DataGrid ItemsSource="{Binding TransactionToEdit.SisterTransactions}"
AutoGenerateColumns="False">
<wpftkit:DataGrid.Columns>
<wpftkit:DataGridComboBoxColumn Header="Account" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}, diagnostics:PresentationTraceSources.TraceLevel=High}, Path=DataContext.Accounts}" DisplayMemberPath="Name"/>
</wpftkit:DataGrid.Columns>
</wpftkit:DataGrid>
Кроме того, окно вывода Visual Studio показывает следующее сообщение об ошибке:
System.Windows.Data Error: 4 : Cannot find source for binding with
reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.StackPanel', AncestorLevel='1''.
BindingExpression:Path=DataContext.Accounts; DataItem=null; target element is
'DataGridComboBoxColumn' (HashCode=25733404); target property is
'ItemsSource' (type 'IEnumerable')
Однако следующий код работает как ожидается (падение в ComboBoxes' списках правильно заполняется):
<ItemsControl ItemsSource="{Binding TransactionToEdit.SisterTransactions}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=DataContext.Accounts, diagnostics:PresentationTraceSources.TraceLevel=High}" DisplayMemberPath="Name"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Обратите внимание, что как DataGrid и ItemsControl имеют одинаковые строки ItemsSource. Так же делают DataGridComboBoxColumn и ComboBox. Один элемент управления связывается правильно, а другой - нет.
Почему данные DataGridComboBoxColumn ItemsSource не связываются правильно?
Спасибо,
Бену
FYI, diagnostics
определяется как xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
У меня такая же проблема !! DataGridComboBoxColumn - это просто испорченная вещь! – Shimmy