1

我刚开始使用 WPF,我不知道如何制作可滚动列表。我希望能够在其中放置一个自定义对象,然后横向滚动。

有没有人可能知道从哪里开始?

4

1 回答 1

1

水平ListBox滚动非常简单:

<ListBox Margin="20">
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <!-- If you need Virtualization then check up on that topic accordingly and you'd need to switch the following StackPanel to a VirtualizingStackPanel -->
      <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
  <ListBoxItem Content="Something A" />
  <ListBoxItem Content="Something B" />
  <ListBoxItem Content="Something C" />
  <ListBoxItem Content="Something D" />
  <ListBoxItem Content="Something E" />
  <ListBoxItem Content="Something F" />
</ListBox>

至于自定义对象部分,请先尝试一些使用ListBox控件的基本示例,例如这些

然后,您几乎只需将您的自定义对象集合绑定到ListBox通过它ItemSource,然后DataTemplate在 xaml 中定义,这将有助于可视化您的自定义对象。

Binding^^ 语句( , ItemSource, )中的几乎每个技术词都是DataTemplate您首先要理解的,并且您可以通过搜索找到每个技术的广泛帮助,而不是新事物。

于 2013-07-06T17:17:29.037 回答