尝试使用 ItemsControl.AlternationIndex 显示列表中的行索引

2024-03-12

我有以下 XAML,旨在将行号放在左列中,但所有输出都是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"
    />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试使用 ItemsControl.AlternationIndex 显示列表中的行索引 的相关文章

随机推荐