views:

40

answers:

1

Hi All,

I want to show multiple columns in the list box. I have referred the following link http://stackoverflow.com/questions/908089/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  A: 

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.

Josh Einstein