2012-01-12 75 views
0

我們知道ListBox的ItemsPanelTemplate是VirtualizingStackPanel。我爲我的ListBox定義了一個Style。 ListBox虛擬化無法工作。我能做什麼?Windows Phone風格使ListBox的虛擬化禁用。如何恢復虛擬化?

<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> 

回答

-1

在您的ControlTemplate來改變你的<StackPanel><VirtualizingStackPanel>而且應該這樣做。

+0

變化,該項目無法正常工作。 – 2012-01-13 02:25:38

1

嘗試改變控件模板:

<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> 
+0

這工作。但是如果我想將ItemsPresenter放置在邊框中呢? – onmyway133 2012-12-21 10:18:18

+0

我沒有嘗試過。但是你已經在ScrollViewer中擁有所有與邊界相關的屬性,所以也許你不需要額外的邊框。如果你真的需要幾個邊框,你可以將ScrollViewer放在邊框中,它應該可以工作。虛擬化基於滾動,因此ScrollViewer中的所有內容都不應該影響它。 – notacat 2012-12-21 15:11:01