2010-07-05 4 views
2

WPFToolkit의 DataGrid 컨트롤 (및 C#/.Net 3.5)을 사용하여 레코드 당 ComboBox를 표시하려고합니다. 아래의 코드로, 선택 상자가 표시하지만, 자신의 드롭 다운이 항목이 포함하지 : 그러나DataGridComboBoxColumn ItemsSource를 RelativeSource에 바인딩 FindAncestor가 작동하지 않습니다.

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') 

가, 다음 코드로 작동합니다 또한

<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> 

을, 비주얼 스튜디오의 출력 창에 다음과 같은 오류를 보여줍니다 예상 (리스트 다운 선택 상자 '드롭이 제대로 설치) : DataGrid에와 ItemsControl에 모두 동일한 ItemsSource 문자열을 가지고

<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> 

참고. DataGridComboBoxColumn과 ComboBox도 마찬가지입니다. 하나의 컨트롤이 올바르게 바인딩되고 다른 하나는 바인딩되지 않습니다.

왜 DataGridComboBoxColumn ItemsSource가 제대로 바인딩되지 않습니까?

참고로, diagnosticsxmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"으로 정의된다
벤에게 감사

+0

동일한 문제가 발생했습니다. DataGridComboBoxColumn은 손상된 것입니다! – Shimmy

답변

3

재미있는 ... 나는 콤보 상자를 포함하는 사용자 정의의 DataGridColumn를 만들고 위에 주어진 같은 ItemsSource 바인딩 문자열을 사용하는 경우 , 작동합니다.

<wpftkit:DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
    <ComboBox SelectedItem="{Binding Account}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=DataContext.Accounts}"  DisplayMemberPath="Name" /> 
    </DataTemplate> 
</wpftkit:DataGridTemplateColumn.CellTemplate> 
+1

ComboBox를 CellTemplate에 넣으면 행이 편집 모드로 전환 될 때 ComboBox가 선택한 값을 잃는 등의 이상한 일이 발생할 수 있다는 것을 발견했습니다. 이에 대한 간단한 해결책은 CellTemplate에 TextBlock을 표시 한 다음 ComboBox를 CellEditingTemplate에 배치하는 것입니다. –

+1

버그입니다. 제기되었습니다. –

관련 문제