列表框中的WPF组合框文本
我在列表框中有一个组合框列表,如下所示:列表框中的WPF组合框文本,wpf,xaml,mvvm,listbox,Wpf,Xaml,Mvvm,Listbox,我在列表框中有一个组合框列表,如下所示: <ListBox ItemsSource="{Binding Values}"> <ListBox.ItemTemplate> <DataTemplate> <ComboBox ItemsSource="{...}" IsTextSearchEnabled="True" IsEditable="True"/>
<ListBox ItemsSource="{Binding Values}">
<ListBox.ItemTemplate>
<DataTemplate>
<ComboBox ItemsSource="{...}" IsTextSearchEnabled="True" IsEditable="True"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的列表框项目的值在我的ViewModel中定义为
public ObservableCollection<string> Values { get; set; }
publicobservableCollection值{get;set;}
如何获取每个组合框的文本以显示特定列表框项的值
(也就是说,如果值是{“a”、“b”、“c”},我想要一个包含3个组合框的列表,显示“a”、“b”和“c”)试试这个
<ListBox ItemsSource="{Binding Values}">
<ListBox.ItemTemplate>
<DataTemplate>
<ComboBox Text="{Binding Mode=OneWay}" ... />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这里的想法是,DataTemplate的隐含DataContext将是当前列表框项。通过指定没有路径的绑定,将文本绑定到值“a”、“b”或“c”