Reputation: 5343
I want to show multiple columns in the list box. I have referred the following link Using WrapPanel and ScrollViewer to give a multi-column Listbox in WPF.
Problem:
I want to scroll the content using repeat button. How to control the listbox scrollbar using button.
Code:
<ListBox Name="lbTrack" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="14" Margin="10" Text="{Binding TrackName}" /> </StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Vertical"></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Upvotes: 1
Views: 6020
Reputation: 69262
Yes, that will work fine. Is there a problem you're having with it?
EDIT: In response to the updated question... In order to programmatically scroll the ListBox you can use the UI Automation framework. Below is some Silverlight code that I found that should work for WPF as well.
var automationPeer = FrameworkElementAutomationPeer.FromElement(element) ??
FrameworkElementAutomationPeer.CreatePeerForElement(element);
var scrollProvider = automationPeer.GetPattern(PatternInterface.Scroll) as IScrollProvider;
if (scrollProvider != null) {
scrollProvider.Scroll(horizontalScrollAmount, verticalScrollAmount);
}
It may also be possible to get this to work by pointing the ScrollBar.LineLeftCommand and ScrollBar.LineRightCommand at the ScrollViewer nested in the ListBox's template but I wasn't able to get that working and I don't know if you could do that without code anyway.
Upvotes: 2