I have a scrollviewer control. Its coding
<Window.Resources>
<DataTemplate x:Key="listBoxItemTemplate">
<TextBlock />
</DataTemplate>
<ItemsPanelTemplate x:Key="itemsPanelTemplate">
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0"/>
<RowDefinition/>
</Grid.RowDefinitions>
<RepeatButton x:Name="LineLeftButton"
Grid.Column="0"
Grid.Row="1"
Content="<"
Command="{x:Static ScrollBar.LineLeftCommand}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<RepeatButton x:Name="LineRightButton"
Grid.Column="2"
Grid.Row="1"
Content=">"
Command="{x:Static ScrollBar.LineRightCommand}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<ScrollViewer Grid.Column="1" Grid.Row="1" x:Name="scrollViewer"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden">
<ListBox Name="lst2"
Margin="0,0,0,0"
VerticalAlignment="Stretch"
ItemsPanel="{StaticResource itemsPanelTemplate}"/>
</ScrollViewer>
</Grid>
I want to disable repeat buttons when there is no data at that end.
That is to say when I am scrolling my Listbox data and at the end when no data is available at that particular side (i.e., left, right) then that side RepeatButton will be disabled. When I am scrolling reverse then the said RepeatButton will be enabled.
I am showing a graphical representation here. I am sure that can clarify properly.
Image1:
Please check the RepeatButton is disabled at the left side as no data to be scrolled at left.
Image2:
Please check the RepeatButton is disabled at the right side now as no data to be scrolled at right.
This type of scrolling is what I am trying to achieve. I read Wpf disable repeatbuttons when scrolled to top/bottom but of no use.
Yes, it is easy.
<ListBox ScrollBar.Scroll="event_handler" />
Add the detection and change properties accordingly.
}
Alternatiely, ScrollViewer might expose ScrollBar.Scroll event too and you dont have to subclass/make new properties. YOu can do the logic inside scroll_handler and change commands CanExecute.