문제

I am trying to use a ComboBox in a DataGrid CellEditingTemplate, binding to an existing DataTable. When I double click the item, the ComboBox displays, but there is no data in it. I've researched different options for a couple of days, but nothing seems to work.

<DataGridTemplateColumn Header=" Venue" CanUserSort="False">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Venue}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox  ItemsSource="{Binding Path=dtVenues, ElementName=MyWindow}"
                       DisplayMemberPath="Venue" 
                       SelectedValuePath="Venue"
                       Text="{Binding Venue}"/> 
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

The DataTable dtVenues is declared as Public in code behind (VB). Can anyone please point me in the right direction for a solution.

도움이 되었습니까?

해결책

I'm guessing that you've declared the dtVenues collection for your ComboBoxes in the code behind of your Window and set the Window.DataContext property value to the code behind class in one way or another. If that is true, then I believe that you need to change your Binding slightly to address the Window.DataContext:

<ComboBox ItemsSource="{Binding Path=DataContext.dtVenues, ElementName=MyWindow}"... />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top