好的,我看了其他问题,似乎没有得到我的答案,希望这里有人可以回答。
非常简单的问题:为什么 DisplayMemberPath 属性不能绑定到项?
<ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PromptList}" DisplayMemberPath="{Binding Name}" SelectedItem="{Binding Prompt}"/>
跟踪输出显示它试图绑定到包含IEnumerable的类,而不是IEnumerable中的实际项。我困惑于一种简单的方法可以填充一个组合框,而不必在XAML中添加大量代码。它只是调用itemssource中对象的ToString()。我有一个解决方法,就是:
<ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PromptList}" SelectedItem="{Binding Prompt}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
但我认为这对于如此简单的任务来说太繁琐了。我可以使用相对源绑定吗?