none
Change Scroll amount with ScrollViewer RRS feed

  • Question

  • I have a scroll viewer that i want to scroll a little more than the LineDownCommand, but a little less than the PageDownCommand. Is there any way to customize this. Ill post the style I use for the scroll viewer. Any help i really appreciate. thanks

        <Style TargetType="{x:Type ScrollViewer}" x:Key="ButtonOnlyScrollViewer"
                <Setter Property="Template"
                    <Setter.Value> 
                        <ControlTemplate TargetType="{x:Type ScrollViewer}"
                            <Grid Name="GridListArrows"
                                <Grid.RowDefinitions> 
                                    <RowDefinition Height="*"/> 
                                    <RowDefinition Height="*"/> 
                                </Grid.RowDefinitions> 
                                <Grid.ColumnDefinitions> 
                                    <ColumnDefinition Width="*" /> 
                                    <ColumnDefinition Width=".2*"/> 
                                </Grid.ColumnDefinitions> 
                                <RepeatButton Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch"  Content="ScrollUp"  
                                  Command="ScrollBar.PageUpCommand" Style="{DynamicResource ArrowUpStyle}" VerticalAlignment="Top"/> 
                                <Border BorderBrush="#268cd8" BorderThickness="1" Height="auto" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"
                                    <ScrollContentPresenter Grid.Row="0" Grid.RowSpan="2" Content="{TemplateBinding Content}" Grid.Column="0" 
                                            ScrollViewer.VerticalScrollBarVisibility ="auto"/> 
                                </Border> 
                                <RepeatButton Grid.Row="1" Grid.Column="1" Content="ScrollDown"  
                                  Command="ScrollBar.PageDownCommand" Style="{DynamicResource ArrowDownStyle}" VerticalAlignment="Bottom"/> 
                            </Grid> 
                        </ControlTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 

    Thursday, September 11, 2008 2:00 PM

Answers

  • You can use the following code to set the SmallChange property:

    ScrollBar verticalScrollBar = scrollViewer.Template.FindName("PART_VerticalScrollBar", scrollViewer) as ScrollBar;
    verticalScrollBar.SmallChange = 5;

    Hope this helps
    • Marked as answer by Marco Zhou Thursday, September 18, 2008 10:10 AM
    Wednesday, September 17, 2008 2:58 AM

All replies

  • -> I have a scroll viewer that i want to scroll a little more than the LineDownCommand, but a little less than the PageDownCommand.

    Could you please describe what you mean by above statement? Do you mean changing the ScrollBar.SmallChange property to support custom scrolling behaviour?

    Thanks
    Tuesday, September 16, 2008 9:22 AM
  • im using a scroll viewer, so there isnt a smallchange property on the scroll viewer, just on the scroll bar, right?? if there is a way to access the smallchange property for a scrollviewer, I'm all ears :) (and eyes) thanks.
    • Edited by heyheyyeah Tuesday, September 16, 2008 4:01 PM
    Tuesday, September 16, 2008 4:00 PM

  • You can use the LineUpCommand and LineDownCommand instead on PageUpCommand and PageDownCommand.

    Vko
    Tuesday, September 16, 2008 7:27 PM
  • You can use the following code to set the SmallChange property:

    ScrollBar verticalScrollBar = scrollViewer.Template.FindName("PART_VerticalScrollBar", scrollViewer) as ScrollBar;
    verticalScrollBar.SmallChange = 5;

    Hope this helps
    • Marked as answer by Marco Zhou Thursday, September 18, 2008 10:10 AM
    Wednesday, September 17, 2008 2:58 AM
  • i really appreciate your help but I'm getting an "Object reference not set to an instance of an object." error. ill post the code i used from what you posted. if you have any other info i would really appreciate it. thanks

    Dim verticalScrollbar As ScrollBar = scrolltest.Template.FindName("ButtonOnlyScrollViewer", scrolltest) 
    verticalScrollbar.SmallChange = 5 

    scrolltest is the name of the ScrollViewer.
    Wednesday, September 17, 2008 3:07 PM
  • Please call ScrollViewer.ApplyTemplate() method before using FindName to find the named ScrollBar within its control template, or you could hook up to ScrollViewer.Loaded event to retrieve the named ScrollBar instance.

    Hope this helps
    Thursday, September 18, 2008 3:28 AM