Windows Phone 风格使 ListBox 的虚拟化被禁用.如何恢复虚拟化? [英] Windows Phone Style make ListBox ' s Virtualizing disabled . how to recover Virtualizing?

查看:26
本文介绍了Windows Phone 风格使 ListBox 的虚拟化被禁用.如何恢复虚拟化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道 ListBox 的 ItemsPanelTemplate 是 VirtualizingStackPanel.我为我的列表框定义了一个样式.ListBox 虚拟化无法工作.我能做什么?

We know ListBox's ItemsPanelTemplate is VirtualizingStackPanel. I define a Style for my ListBox. The ListBox Virtualizing can't work. What can I do?

<Style x:Key="ListBoxStyle" 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>
                            <ItemsPresenter/>
                            <HyperlinkButton Content="Add More"
                                             FontSize="25"
                                             Grid.Row="1"
                                             Name="hybtnAddMerchant"
                                             Click="hybtnAddMerchant_Click"
                                             VerticalAlignment="Bottom"/>
                        </StackPanel>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

推荐答案

尝试更改 ControlTemplate:

try to change ControlTemplate:

<ControlTemplate TargetType="ListBox"> 
  <Grid>
     <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto"/>
     </Grid.RowDefinitions>
     <ScrollViewer x:Name="ScrollViewer" Grid.Row="0"
                   BorderBrush="{TemplateBinding BorderBrush}"  
                   BorderThickness="{TemplateBinding BorderThickness}"  
                   Background="{TemplateBinding Background}"  
                   Foreground="{TemplateBinding Foreground}"  
                   Padding="{TemplateBinding Padding}"> 
           <ItemsPresenter/> 
      </ScrollViewer> 
      <HyperlinkButton Content="Add More" FontSize="25" 
             Grid.Row="1" Name="hybtnAddMerchant" Click="hybtnAddMerchant_Click" VerticalAlignment="Bottom"/> 
  </Grid>
</ControlTemplate> 

这篇关于Windows Phone 风格使 ListBox 的虚拟化被禁用.如何恢复虚拟化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆