1

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>

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.