ComboBox在CellEditingTemplate [英] ComboBox in CellEditingTemplate
问题描述
我想在DataGrid CellEditingTemplate中使用ComboBox,绑定到现有的DataTable。当我双击该项目时,ComboBox显示,但其中没有数据。我已经研究了不同的选项几天,但没有什么似乎工作。
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>
DataTable dtVenues在代码后面(VB)中声明为Public。任何人都可以指出正确的方向来解决问题。
The DataTable dtVenues is declared as Public in code behind (VB). Can anyone please point me in the right direction for a solution.
推荐答案
我猜你已经宣布窗口中的代码中的
并以某种方式将 Window.DataContext
属性值设置为类后面的代码。如果这是真的,那么我相信你需要改变你的绑定
稍微处理 Window.DataContext
:
I'm guessing that you've declared the dtVenues
collection for your ComboBox
es 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}"... />
这篇关于ComboBox在CellEditingTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!