Home > Enterprise >  How to fill a ComboBox with indexes of bound collection?
How to fill a ComboBox with indexes of bound collection?

Time:12-06

I want to create a ComboBox with contents of TextBlocks that are in the from "Sample 01", where the number is replaced with the index of the item (from 1).

Below is roughly my current code:

<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>

I am using INPC to ensure that changes on the VM reflect the View, as I am using MVVM. How can I achieve my desired result? I have considered converters, but am not sure it fits in what I am wanting to do, or if there is a better way.

Does this at all relate to ComboBox with sample data.

  • Related