Search code examples
wpfscrollbardatatemplatescrollitemscontrol

Setting scroll extent of ScrollViewer in wpf


I am using a ScrollViewer in WPF. My XAML is as follows ::

<ScrollViewer HorizontalScrollBarVisibility="Auto" x:Name="ScrollProcess">

   <ItemsControl ItemsSource="{Binding Steps}">

        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"></StackPanel>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                  <TextBlock>Test Text</TextBlock>
            </DataTemplate>
        </ItemsControl.ItemTemplate>

    </ItemsControl>

</ScrollViewer>

I want to know how to set the scrollbar to the selected TextBlock (say around 25 TextBlocks gets displayed. I have to move the scrollbar to 15th TextBlock)


Solution

  • textBox15.BringIntoView();
    

    FrameworkElement.BringIntoView Method