3

내 ListBox에 헤더를 추가하고 템플릿을 사용하여이 작업을 수행합니다. 문제는 목록 상자의 서식 파일을 확장하면 목록 상자의 virtualizingstackpanel이 예상대로 작동하지 않는 것 같습니다. 스크롤하기 전에 모든 내용을로드합니다.목록 상자의 스크롤 뷰어에 헤더 추가 및 virtualizingStackPanel (wp7) 유지

(VirtualizingStackPanel stops working when overriding the default control template for ScrollViewer)와 같은 stackoverflow에서 몇 가지 관련 질문을 발견했지만 거기에 주어진 솔루션은 WP7에 적용 할 수 없습니다 : 나는 scrollviewer의 "CanContentScroll"라는 속성을 찾을 수 없습니다.

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

답변

2

솔직히 말해서, 나는 정말 실제 문제가 여기 모르겠어요 내 코드; VirtualizingStackPanel은 여전히 ​​시각적 트리에 있지만 실제로 추가 된 항목이없는 것으로 보입니다. 좋은 소식은 좋은 소식인데 그 대신에 ScrollViewer의 기본 스타일을 변경하여 머리글을 그 자리에 배치함으로써 두 스타일의 결과를 얻을 수 있다는 것을 알았습니다.

<Style x:Key="ScrollViewerStyle1" TargetType="ScrollViewer"> 
    <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="Padding" Value="0"/> 
    <Setter Property="BorderThickness" Value="0"/> 
    <Setter Property="BorderBrush" Value="Transparent"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ScrollViewer"> 
       <Border BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}" 
         Background="{TemplateBinding Background}"> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="ScrollStates"> 
          <VisualStateGroup.Transitions> 
           <VisualTransition GeneratedDuration="00:00:00.5" /> 
          </VisualStateGroup.Transitions> 
          <VisualState x:Name="Scrolling"> 
           <Storyboard> 
            <DoubleAnimation Storyboard.TargetName="VerticalScrollBar" 
                 Storyboard.TargetProperty="Opacity" 
                 To="1" 
                 Duration="0" /> 
            <DoubleAnimation Storyboard.TargetName="HorizontalScrollBar" 
                 Storyboard.TargetProperty="Opacity" 
                 To="1" 
                 Duration="0" /> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="NotScrolling"> 
          </VisualState> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Grid Margin="{TemplateBinding Padding}"> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="*" /> 
         </Grid.RowDefinitions> 
         <TextBlock Text="Header" Style="{StaticResource PhoneTextLargeStyle}"/> 
         <ScrollContentPresenter x:Name="ScrollContentPresenter" 
               Grid.Row="1" 
               Content="{TemplateBinding Content}" 
               ContentTemplate="{TemplateBinding ContentTemplate}" /> 
         <ScrollBar x:Name="VerticalScrollBar" 
            Grid.RowSpan="2" 
            IsHitTestVisible="False" 
            Opacity="0" 
            Height="Auto" 
            Width="5" 
            HorizontalAlignment="Right" 
            VerticalAlignment="Stretch" 
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" 
            IsTabStop="False" 
            Maximum="{TemplateBinding ScrollableHeight}" 
            Minimum="0" 
            Value="{TemplateBinding VerticalOffset}" 
            Orientation="Vertical" 
            ViewportSize="{TemplateBinding ViewportHeight}" /> 
         <ScrollBar x:Name="HorizontalScrollBar" 
            Grid.RowSpan="2" 
            IsHitTestVisible="False" 
            Opacity="0" 
            Width="Auto" 
            Height="5" 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Bottom" 
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" 
            IsTabStop="False" 
            Maximum="{TemplateBinding ScrollableWidth}" 
            Minimum="0" 
            Value="{TemplateBinding HorizontalOffset}" 
            Orientation="Horizontal" 
            ViewportSize="{TemplateBinding ViewportWidth}" /> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
<Style x:Key="ListBoxStyle2" 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" 
           Grid.Row="1" 
           Style="{StaticResource ScrollViewerStyle1}" 
           Foreground="{TemplateBinding Foreground}" 
           Background="{TemplateBinding Background}" 
           BorderBrush="{TemplateBinding BorderBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Padding="{TemplateBinding Padding}"> 
        <ItemsPresenter /> 
       </ScrollViewer> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style>
+0

솔루션을 게시 해 주셔서 감사합니다. 매력처럼 작동합니다. –