WPF MultiColumn ListBox显示索引

时间:2016-04-10 14:19:11

标签: c# wpf listbox

我有一个多列ListBox,如下所示。

<ListBox x:Name="lstQuestions" HorizontalAlignment="Left" Height="544" VerticalAlignment="Top" Width="175" Margin="0,0,0,-0.5" SelectionChanged="lstQuestions_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="20"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding qID}"/>
                                <Image Source="{Binding imgPath}" Width="140" Height="50" Stretch="UniformToFill" Grid.Column="1"/>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

我想在第一栏中显示索引号(例如1,2,3 ......)而不是<TextBlock Text="{Binding qID}"/>,我该怎么做?

编辑:背后的绑定代码

 public class QList
{
    public string qID { get; set; }
    public string imgPath { get; set; }
    public int ansCount { get; set; }
    public string rightAns { get; set; }
}

public static List<QList> questions = new List<QList>();

最后一个

lstQuestions.ItemsSource = Test.questions;

前两个名为Test

0 个答案:

没有答案