【问题标题】:Listbox with multiple columns wpf具有多列 wpf 的列表框
【发布时间】:2011-03-15 03:33:16
【问题描述】:

我想在列表框中显示多个列。我已经参考了以下链接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>

【问题讨论】:

    标签: wpf listbox multiple-columns


    【解决方案1】:

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

    编辑:响应更新的问题...为了以编程方式滚动 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 来使其工作,但我无法使其工作,我不知道你是否可以无论如何,无需代码即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多