Just to get you on your way:
This example works only when the items have the same height.
If not, you have to make a list of all Y positions and get the text from that list.
<Window x:Class="WpfApplicationtest2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" SizeChanged="Window_SizeChanged">
<Grid>
<Canvas>
<Border Name="BorderPageNumber" BorderBrush="Black" removed="#66454545">
<TextBlock Name="TextBoxTest" FontSize="22" Width="150" Height="30">Test</TextBlock>
</Border>
</Canvas>
<ScrollViewer Name="ScrollviewerTest" Loaded="ScrollviewerTest_Loaded" ScrollChanged="ScrollviewerTest_ScrollChanged">
<StackPanel Name="StackPanelScrollItems" Orientation="Vertical">
<TextBlock Margin="10,10,0,50" FontSize="22">Test 1</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 2</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 3</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 4</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 5</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 6</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 7</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 8</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 9</TextBlock>
<TextBlock Margin="10,10,0,50" FontSize="22">Test 10</TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
List<point> ContentPositions = new List<point>();
private string GetItemText(int index)
{
return ((TextBlock)StackPanelScrollItems.Children[index]).Text;
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
ScrollviewerTest.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
((TextBlock)StackPanelScrollItems.Children[0]).Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
SetInfoPosition();
}
private void SetInfoPosition()
{
BorderPageNumber.Margin = new Thickness(ScrollviewerTest.ActualWidth - 160, (ScrollviewerTest.ViewportHeight / 2.0) - 30, 0, 0);
}
private void ScrollviewerTest_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
int pageNumber = e.VerticalOffset==0 ? 1 : ((int)(e.VerticalOffset / e.ViewportHeight) + 1);
int itemIndex = e.VerticalOffset == 0 ? 1 : (int)(e.VerticalOffset / (((TextBlock)StackPanelScrollItems.Children[0]).DesiredSize.Height)) + 1;
TextBoxTest.Text = pageNumber.ToString() + " " + GetItemText(itemIndex);
}
private void ScrollviewerTest_Loaded(object sender, RoutedEventArgs e)
{
SetInfoPosition();
}
}
</point></point>