c# - 无论选择什么,ComboBox都会显示System.Data.DataRowView。 ItemTemplate问题

标签 c# wpf xaml mvvm

我有一个ComboBox,它需要在下拉菜单中显示多个字段。但只想存储一个。现在,它可以显示多个字段。但是无论我选择什么,文本框中显示的值都是“System.Data.DataRowView”。有谁知道这是为什么或如何解决?

<ComboBox ItemsSource="{Binding Vwr.Table.Tbl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
  x:Name="Supplier"
  SelectedValuePath="Name"
  SelectedValue="Name"
  IsEditable="True" Style="{StaticResource tabTextBox}"
    DataContext="{Binding parties}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding SupplierChangedCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0}: {1}: {2}">
                        <Binding Path="Name"/>
                        <Binding Path="Funds"/>
                        <Binding Path="Terms"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

最佳答案

在这里找到答案:http://www.shujaat.net/2010/08/wpf-editable-combobox-with-datatemplate.html

解决方案是设置TextSearch.TextPath。就我而言,

TextSearch.TextPath="Name"

更新我的原始代码(为简洁起见,删除了不必要的部分),工作版本在这里
<ComboBox 
  x:Name="Supplier"
  ItemsSource="{Binding Vwr.Table.Tbl}"
  SelectedValuePath="Name"
  SelectedValue="Name"
  IsEditable="True" Style="{StaticResource tabTextBox}"
  TextSearch.TextPath="Name"
  DataContext="{Binding parties}">

希望这对外面的人有所帮助!

关于c# - 无论选择什么,ComboBox都会显示System.Data.DataRowView。 ItemTemplate问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49886815/

相关文章:

WPF DataGrid,Ctrl+C 后复制到剪贴板,OnCopyingRowClipboardContent

wpf - 免费的 XamlPad 替代品

c# - 如何将空值插入数据库?

c# - 无法使用 whis json 反序列化当前 JSON 对象

c# - 类型(我的类)必须是不可空类型才能在泛型方法中用作参数 'T'

c# - 从另一个ViewModel访问属性

wpf - 在 WPF 中正确使用 VirtualizingStackPanel

c# - DataGridRowTemplateColumn - 高效地重构和使用样式?

c# - 我可以在 XAML(.NET 4 Framework 之前)中指定泛型类型吗?

c# - 枚举反射程序集中的集合需要空引用检查吗?