wpf - 如何与 StringFormat 绑定(bind)

标签 wpf xaml

我有一个 ComboBox我绑定(bind)到 IEnumerable<int>来源。

源的值如 12,13,14 但我想要 ComboBoxSelectedValue 显示版本 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/

相关文章:

wpf - 在代码中创建DataTemplate和DataTrigger

wpf - 需要比较 MVVM/WPF/Silverlight Toolkits

.net - 将 WPF Canvas 子项绑定(bind)到 ObservableCollection

c# - XAML 中的组合框选择更改

c# - 在 Windows Phone 8.1 应用程序中过滤 ListView

c# - WPF GridView 上下文菜单

c# - 本地化 Windows Phone 8 'Application Title' 和 'Tile Title' 字符串

c# - 包裹面板项目分隔符 WPF

wpf - 如何将 XAML Storyboard动画添加到 XBAP 中的完整 WPF 自定义控件?

wpf - TextBlock 背景属性删除拉伸(stretch)