尝试使用ItemsControl.AlternationIndex在列表中显示行索引 [英] Trying to use ItemsControl.AlternationIndex to show row index in list

查看:101
本文介绍了尝试使用ItemsControl.AlternationIndex在列表中显示行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XAML,旨在将行号放在左列中,但输出的全部是 0

I've got the following XAML which is intended to put the row number in the left column but all that gets output is 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>

有人可以暗示这里有什么问题吗?

Can anybody suggest what is wrong here?

推荐答案

以下内容符合我的要求

<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, 
           Path=TemplatedParent.(ItemsControl.AlternationIndex)}"
    Margin="0,0,5,0"
    />

这篇关于尝试使用ItemsControl.AlternationIndex在列表中显示行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆