I am trying to make a scroll viewer in which scroll button is visible only when window size is too small to show all the content. I have put some button into a stackpanel which is in the scrollviewer.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
<RowDefinition/>
</Grid.RowDefinitions>
<RepeatButton x:Name="LineLeftButton"
Grid.Column="0"
Grid.Row="0"
Command="{x:Static ScrollBar.LineDownCommand}"
Background="{StaticResource uparrow}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<RepeatButton x:Name="LineRightButton"
Grid.Column="0"
Grid.Row="2"
Background="{StaticResource downarrow}"
Command="{x:Static ScrollBar.LineUpCommand}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<ScrollViewer Grid.Column="1" Grid.Row="1" x:Name="scrollViewer"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden">
<StackPanel Orientation="Vertical">
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
</StackPanel>
</ScrollViewer>
</Grid>
The scroll is working kk but how do you disable it when there are not enough element in the stack such that a scroll is not required?