我有一个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/