我正在尝试使用下面的代码在 WP7 silverlight 中制作水平列表框。项目水平显示,但滚动仍然是垂直的。
我在 wpf 中做错了什么吗?这是 WP7 特有的错误吗?
<Style TargetType="ListBox" x:Name="HorizontalListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"
IsItemsHost="True"
CanHorizontallyScroll="True"
CanVerticallyScroll="False"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
编辑:我遗漏了两个似乎有很大区别的属性。 (解决方案来自 Mick N 接受的答案中的第二个链接。)
<Style TargetType="ListBox" x:Name="HorizontalListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" CanHorizontallyScroll="True" CanVerticallyScroll="False"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
</Style>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" >
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="0,6,-196,0" Height="Auto" Name="imageScroll">
<ListBox x:Name="imageBox" Margin="12,0,0,0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" >
<StackPanel.RenderTransform>
<TranslateTransform
X="0" />
</StackPanel.RenderTransform>
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Avatar}" Width="240" Stretch="Fill" Height=" 100" />
<!--<TextBlock TextWrapping="Wrap" Text="{Binding Titulo}" FontSize="35" VerticalAlignment="Center" Margin="0,10" />-->
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
这是对我有用的代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)