3
我想向我的ListBoxes添加标题,并使用模板执行此操作。 问题是,如果我扩展列表框的模板,似乎列表框的virtualizingstackpanel不再按预期工作:它会加载所有内容,然后才能滚动它。将标题添加到列表框的滚动查看器并保留virtualizingStackPanel(wp7)
我在这样的计算器中发现了一些相关问题(VirtualizingStackPanel stops working when overriding the default control template for ScrollViewer),但是给出的解决方案不能应用于WP7:我找不到名为“CanContentScroll”的scrollviewer属性。
我的代码
<Style x:Key="ListBoxStyle1" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
Padding="{TemplateBinding Padding}">
<StackPanel>
<TextBlock Text="..."/>
<ItemsPresenter/>
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
感谢您发布解决方案。奇迹般有效 – 2012-01-10 20:33:19