您需要做的第一件事是創建一個包含您的ComboBox的數據模板,在這種情況下,我已經將ItemsSource綁定到主窗口上的DependencyProperty。這包含演示模型,其中有一個名爲ComboSource的屬性。 SelectedValue已經通過ListViewItem的DataContext綁定到一個包含選定值的屬性。
<ListView.Resources>
<DataTemplate x:Key="comboBoxTemplate">
<ComboBox
ItemsSource="{Binding
Path=ModelData.ComboSource,
RelativeSource={RelativeSource AncestorType=Window}}"
SelectedValue="{Binding
Path=DataContext.Selection,
RelativeSource={RelativeSource AncestorType=ListViewItem}}"
DisplayMemberPath="Item"
SelectedValuePath="Id"
/>
</DataTemplate>
</ListView.Resources>
然後,你將需要在GridViewColumn
<GridViewColumn
Header="Selection"
Width="160"
CellTemplate="{StaticResource comboBoxTemplate}"
/>
坦克從CellTemplate引用此!這非常有幫助 – KaJo 2008-11-14 07:28:43