尝试使用ItemsControl

尝试使用ItemsControl

本文介绍了尝试使用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在列表中显示行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:09