Question: I'm plotting a histogram of a grayscale image using an array of 256 values. Im doing so by creating my own chart with 256 vertical rectangles (columns). My aim is that when I mouse over one rectangle I get its index value, its index from the array it lies in, like if I mouse over the 200th rectangle I get 200 in a small text box near cursor, like how ToolTip should perform. The problem is that I don't find the proper binding for ToolTip to get this working. I think the solution lies in the proper use of **AlternationCount** / **AlternationIndex**

Here is may XAML code, maybe someone can give me a fix for it:

```
<ItemsControl Grid.Row="1" ItemsSource="{Binding HistogramValues}" AlternationCount="{Binding Path=HistogramValues.Count}">              
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Rectangle Height="{Binding }" ToolTip="{Binding AlternationIndex, RelativeSource={RelativeSource AncestorType=ItemsControl}}" Width="2" VerticalAlignment="Bottom" Fill="Black"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate> 
</ItemsControl>

```

where in view model I have:

```
public float[] HistogramValues { get; set; }

```

I've found this useful post 
[Numbered listbox](https://stackoverflow.com/questions/745568/numbered-listbox/748383)
but I still cant make it run for my case, I'm confused about that **ItemTemplate** and **TemplatedParent** which I dont know if I need or if I need the template how should I code this.

Answer: 
If you are not ok with converters you can use this,

```
 <ItemsControl Grid.Row="1" ItemsSource="{Binding Collection}" AlternationCount="{Binding Path=Collection.Count}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock  Text="{Binding}" ToolTip="{Binding Path=(ItemsControl.AlternationIndex),   RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentPresenter}}">
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

```

Since AlternationIndex is attached property, it should be covered with "()".
If you dont specify source in a binding, it always binds to datacontext.

Do this

```
ToolTip="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType=ContentPresenter}}" 

```