Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试使用ItemsControl.AlternationIndex在列表中显示行索引_C#_Wpf_Listbox - Fatal编程技术网

C# 尝试使用ItemsControl.AlternationIndex在列表中显示行索引

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>

我得到了下面的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"
    />

以下内容符合我的要求

<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}”