我有一个 ComboBox
我绑定(bind)到 IEnumerable<int>
来源。
源的值如 12,13,14 但我想要 ComboBox
以 SelectedValue
显示版本 12、版本 13、版本 14 等仍然是 12、13 和 14。
现在我正在修改 Source 以向其添加版本,然后将 ComboBox 绑定(bind)到 IEnumerable。
XAML
<ComboBox x:Name="ComboBoxVersions"
SelectedIndex="0"
SelectionChanged="ComboBoxVersions_OnSelectionChanged"
ItemsSource="{Binding EnvironmentVersions}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
最佳答案
你可以使用这样的东西
<TextBlock Text="{Binding StringFormat=Version: {0}}" />
关于wpf - 如何与 StringFormat 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31983715/