【发布时间】:2022-01-08 13:55:26
【问题描述】:
我想创建一个ComboBox,其内容为“Sample 01”中的TextBlocks,其中数字被替换为项目的索引(从1开始)。
下面大致是我目前的代码:
<ComboBox
x:Name="ComboSampleItems"
Grid.Column="0"
Height="20"
HorizontalAlignment="Stretch"
ItemsSource="{Binding ReportModel.SampleData}"
SelectedItem="{Binding SelectedSampleScans}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ????, StringFormat=Something here?}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我使用INPC 来确保VM 上的更改反映视图,因为我使用的是MVVM。
我怎样才能达到我想要的结果?我考虑过转换器,但不确定它是否适合我想做的事情,或者是否有更好的方法。
这是否与this topic? 有关系
【问题讨论】:
标签: c# wpf xaml data-binding combobox