1

我想在列表框中显示多列。我参考了以下链接Using WrapPanel and ScrollViewer to give a multi-column Listbox in WPF

问题:

我想使用重复按钮滚动内容。如何使用按钮控制列表框滚动条。

代码:

  <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>
4

1 回答 1

2

是的,这会很好。你有问题吗?

编辑:响应更新的问题...为了以编程方式滚动 ListBox,您可以使用 UI 自动化框架。下面是一些我发现也适用于 WPF 的 Silverlight 代码。

var automationPeer = FrameworkElementAutomationPeer.FromElement(element) ??
                     FrameworkElementAutomationPeer.CreatePeerForElement(element);

var scrollProvider = automationPeer.GetPattern(PatternInterface.Scroll) as IScrollProvider;
if (scrollProvider != null) {
    scrollProvider.Scroll(horizontalScrollAmount, verticalScrollAmount);
}

也可以通过将ScrollBar.LineLeftCommandScrollBar.LineRightCommand指向嵌套在 ListBox 模板中的 ScrollViewer 来使其工作,但我无法让它工作,我不知道你是否可以做到这一点反正代码。

于 2010-07-13T05:36:36.637 回答