【问题标题】:Can't display selecteditem无法显示所选项目
【发布时间】:2015-04-14 14:59:17
【问题描述】:

我的组合框在列表中正确显示我的所有数据,但不显示所选项目,而不是我只有我的对象的名称。

没有项目模板它工作正常,但我需要它来显示我的数据。我做错什么了吗?如何让我选择的项目显示在同一个 dataTemplate 中?

<ComboBox Grid.Row="2" 
          Grid.Column="1" 
          Style="{StaticResource myComboBox}" 
          x:Name="ComboBoxProtocole" 
          IsEditable="True" 
          IsTextSearchEnabled="True"
          TextSearch.Text="labelFull"
          ItemsSource="{Binding}"
          >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding labelShort}" FontSize="12"/>
                <TextBlock Text="{Binding labelFull}" FontSize="10" />
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

【问题讨论】:

  • itemsSource 绑定到什么?
  • 它绑定到我的数据上下文,我的对象的可观察集合

标签: wpf xaml selecteditem


【解决方案1】:

您需要设置 TextSearch.TextPath="labelFull"

<ComboBox Grid.Row="2" 
      Grid.Column="1"           
      x:Name="ComboBoxProtocole" 
      IsEditable="True" 
      IsTextSearchEnabled="True"
      TextSearch.TextPath="labelFull"
      ItemsSource="{Binding}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{Binding labelShort}" FontSize="12"/>
                    <TextBlock Text="{Binding labelFull}" FontSize="10" />
                </StackPanel>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

【讨论】:

  • 原来是TextPath,我的错误没看到!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-30
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多