C# 尝试使用ItemsControl.AlternationIndex在列表中显示行索引
我得到了下面的XAML,它打算将行号放在左列中,但得到的输出是C# 尝试使用ItemsControl.AlternationIndex在列表中显示行索引,c#,wpf,listbox,C#,Wpf,Listbox,我得到了下面的XAML,它打算将行号放在左列中,但得到的输出是0 <ListBox VirtualizingPanel.VirtualizationMode="Recycling" ItemsSource="{Binding MoineauPumpFlanks.Stator.Flank.Boundary, Mode=OneWay}" AlternationCount="2147483647" > <ListBox.ItemTemplate>
0
<ListBox
VirtualizingPanel.VirtualizationMode="Recycling"
ItemsSource="{Binding MoineauPumpFlanks.Stator.Flank.Boundary, Mode=OneWay}"
AlternationCount="2147483647"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock
Text="{Binding RelativeSource={RelativeSource Mode=Self},
Path=(ItemsControl.AlternationIndex)}"
Margin="0,0,5,0"
/>
<!-- A custom control of mine -->
<Controls:LabelForPoint Point="{Binding}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
有人能告诉我这里出了什么问题吗?下面就是我想要的
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=TemplatedParent.(ItemsControl.AlternationIndex)}"
Margin="0,0,5,0"
/>
以下内容符合我的要求
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=TemplatedParent.(ItemsControl.AlternationIndex)}"
Margin="0,0,5,0"
/>
也许这个绑定更适合阅读:Text=“{binding(ItemsControl.alternationadex),RelativeSource={RelativeSource-AncestorType=ListBoxItem}}”
也许这个绑定更适合阅读:Text=“{binding(ItemsControl.alternationadex),RelativeSource={RelativeSource-AncestorType=ListBoxItem}”
。