有办法通过绑定到一个WrapPanel来填充Silverlight工具包的ObservableCollection吗?到目前为止,我看到的所有示例,包括工具箱示例本身,要么以编程方式填充WrapPanel,要么在XAML中显式地添加每个项。
谢谢你的帮忙!
编辑:在Geert van Horrik's advice之后,我尝试使用ItemsControl通过绑定加载WrapPanel。这是XAML:
<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并公开了两个公共属性- ImageSource和BorderBrush。
我正在将构造函数中的DataContext为UserControl设置为SelectionContent。但是这不起作用,而且WrapPanel没有显示任何东西。
发布于 2011-01-04 07:40:30
您应该使用ItemsControl。然后,可以将WrapPanel设置为items面板。
<ItemsControl ItemsSource="{Binding MyItemsSource}">
<ItemsControl.ItemsPanel>
<WrapPanel />
</ItemsControl.ItemsPanel>
</ItemsControl>https://stackoverflow.com/questions/4591096
复制相似问题