有人知道如何将滚动条添加到itemscontrol中包含的wrappanel吗?
答案 0 :(得分:3)
这在这里不起作用,
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ScrollViewer>
<WrapPanel Orientation="Horizontal" />
</ScrollViewer>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
你得到一个讨厌的例外, ItemsPanelTemplate的VisualTree必须包含Panel。 'System.Windows.Controls.ScrollViewer'不是Panel。
答案 1 :(得分:1)
围绕它包裹ScrollViewer标签
<ScrollViewer>
<WrapPanel>
<!-- your other controls here -->
</WrapPanel>
</ScrollViewer>
答案 2 :(得分:0)
此样本(从Kaxaml样本修改)应该可以帮助您:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="flickrdata" Source="http://api.flickr.com/services/feeds/photos_public.gne?tags=flower&lang=en-us&format=rss_200">
<XmlDataProvider.XmlNamespaceManager>
<XmlNamespaceMappingCollection>
<XmlNamespaceMapping Prefix="media" Uri="http://search.yahoo.com/mrss/"/>
</XmlNamespaceMappingCollection>
</XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
<DataTemplate x:Key="itemTemplate">
<Image Width="75" Height="75" Source="{Binding Mode=OneWay, XPath=media:thumbnail/@url}"/>
</DataTemplate>
<ControlTemplate x:Key="controlTemplate" TargetType="{x:Type ItemsControl}">
<WrapPanel IsItemsHost="True" Orientation="Horizontal"/>
</ControlTemplate>
</Grid.Resources>
<ScrollViewer Width="320" Height="225">
<ItemsControl
Width="300"
ItemsSource="{Binding Mode=Default, Source={StaticResource flickrdata}, XPath=/rss/channel/item}"
ItemTemplate="{StaticResource itemTemplate}"
Template="{StaticResource controlTemplate}">
</ItemsControl>
</ScrollViewer>
</Grid>
</Page>