【问题标题】:WPF ComboBox text inside ListBoxListBox 内的 WPF ComboBox 文本
【发布时间】:2010-04-16 22:15:33
【问题描述】:

我在列表框中有一个组合框列表,如下所示:

    <ListBox ItemsSource="{Binding Values}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <ComboBox ItemsSource="{...}" IsTextSearchEnabled="True" IsEditable="True"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

我的列表框 ItemsSouce 的值在我的 ViewModel 中定义为

    public ObservableCollection<string> Values { get; set; }

如何获取每个组合框的文本以显示该特定列表框项的值?

(即如果值是 {"a", "b", "c"} 我想要一个显示 "a"、"b" 和 "c" 的 3 个组合框的列表)

【问题讨论】:

    标签: wpf xaml mvvm listbox


    【解决方案1】:

    试试这个。

    <ListBox ItemsSource="{Binding Values}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <ComboBox Text="{Binding Mode=OneWay}" ... />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    这里的想法是 DataTemplate 的隐含 DataContext 将是当前列表框项。通过指定不带路径的绑定,您将文本绑定到值“a”、“b”或“c”。

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-08
      • 2011-10-13
      • 2013-02-24
      • 1970-01-01
      相关资源
      最近更新 更多