有没有办法填充 Silverlight 工具包的 WrapPanel
通过绑定(bind)到 ObservableCollection
?到目前为止,我看到的所有示例,包括工具包示例本身,都填充了 WrapPanel
以编程方式或通过在 XAML 中显式添加每个项目。
谢谢你的帮助!
编辑 : 关注 Geert van Horrik's advice我尝试使用 ItemsControl
加载 WrapPanel
通过绑定(bind)。这是 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
是 ObservableCollection
出现在此UserControl
的代码在后面。它由 SelectionItem
组成对象,实现 INotifyPropertyChanged
并公开 2 个公共(public)属性 - ImageSource
和 BorderBrush
.我正在设置
DataContext
对于UserControl
在其构造函数中为 SelectionContent
.但这不起作用,WrapPanel
不显示任何内容。
最佳答案
您应该使用 ItemsControl。然后,您可以将 WrapPanel 设置为项目面板。
<ItemsControl ItemsSource="{Binding MyItemsSource}">
<ItemsControl.ItemsPanel>
<WrapPanel />
</ItemsControl.ItemsPanel>
</ItemsControl>
关于silverlight - WP7 WrapPanel & MVVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4591096/