首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP7 WrapPanel & MVVM

WP7 WrapPanel & MVVM
EN

Stack Overflow用户
提问于 2011-01-04 06:10:53
回答 1查看 2K关注 0票数 1

有办法通过绑定到一个WrapPanel来填充Silverlight工具包的ObservableCollection吗?到目前为止,我看到的所有示例,包括工具箱示例本身,要么以编程方式填充WrapPanel,要么在XAML中显式地添加每个项。

谢谢你的帮忙!

编辑:在Geert van Horrik's advice之后,我尝试使用ItemsControl通过绑定加载WrapPanel。这是XAML:

代码语言:javascript
复制
<ScrollViewer VerticalScrollBarVisibility="Auto"
              Height="440"
              Margin="0,12,0,0">

  <ItemsControl ItemsSource="{Binding SelectionContent}">
    <ItemsControl.ItemTemplate>
      <DataTemplate>

        <Border BorderThickness="1"
                CornerRadius="4"
                BorderBrush="{Binding BorderBrush}">

          <toolkit:GestureService.GestureListener>
            <toolkit:GestureListener Tap="OnWrapPanelTapped"
                                     DoubleTap="OnWrapPanelDoubleTapped" />
          </toolkit:GestureService.GestureListener>

          <Image Source="{Binding ImageSource}"
                 MaxHeight="48"
                 MaxWidth="48"
                 Margin="16" />
        </Border>

      </DataTemplate>
    </ItemsControl.ItemTemplate>

    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
        <toolkit:WrapPanel />
      </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
  </ItemsControl>
</ScrollViewer>

SelectionContent是这个UserControl背后的代码中的一个ObservableCollection,它由SelectionItem对象组成,它实现了INotifyPropertyChanged并公开了两个公共属性- ImageSourceBorderBrush

我正在将构造函数中的DataContextUserControl设置为SelectionContent。但是这不起作用,而且WrapPanel没有显示任何东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-04 07:40:30

您应该使用ItemsControl。然后,可以将WrapPanel设置为items面板。

代码语言:javascript
复制
<ItemsControl ItemsSource="{Binding MyItemsSource}">
  <ItemsControl.ItemsPanel>
    <WrapPanel />
  </ItemsControl.ItemsPanel>
</ItemsControl>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4591096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档