2017-02-24 16 views
0

DisabledVerticalOrientationVerticalScrollbarVisibility 세트 ListBoxItemsPanelTemplateWrapPanel를 사용하여, 나는이 수평 방향으로 마우스 휠을 내 콘텐츠를 스크롤 할 수 없습니다.목록 상자 wrappanel 스크롤 verticle 방향 WPF

ListBox를 가로 방향으로 스크롤 할 수 있지만 항목이 창 높이와 관련하여 위쪽에서 아래쪽 방향으로 나타나야하는 것처럼 보이도록 ListBox를 만들고 싶습니다.

항목의 주요 문제는 내가 마우스로 스크롤 할 수 없습니다입니다

1 4 7 10 
2 5 8 11 ... 
3 6 9 12 

아래로 이러한 방식으로 나타납니다. 스크롤바를 사용하면 잘 작동하며 키보드 선택을 사용하면 잘 작동합니다.

는 여기에 내가 무슨 짓을했는지

<ListBox ItemContainerStyle="{StaticResource ResourceKey=ContainerStyle}" Background="{StaticResource StaticBackground}" ItemsSource="{Binding ListSource}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Vertical" ScrollViewer.VerticalScrollBarVisibility="Disabled"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 

Flow of data from top to bottom with horizontal orientation

이가 내 ItemContainerStyle

<Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle"> 
    <Setter Property="ContentTemplate" Value="{StaticResource DT_TestTemplate}" /> 
    <Setter Property="SnapsToDevicePixels" Value="True" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListBoxItem"> 
       <Border x:Name="Border" 
         Margin="5,5,5,5" 
         SnapsToDevicePixels="true"> 
        <Border.Background> 
         <SolidColorBrush Color="Transparent" /> 
        </Border.Background> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="SelectionStates"> 
          <VisualState x:Name="Unselected" > 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
              Storyboard.TargetProperty="(Panel.Background). 
       (SolidColorBrush.Color)"> 
             <EasingColorKeyFrame KeyTime="0" 
            Value="White" /> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Selected"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
              Storyboard.TargetProperty="(Panel.Background). 
       (SolidColorBrush.Color)"> 
             <EasingColorKeyFrame KeyTime="0" 
            Value="#FFF34235" /> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="SelectedUnfocused"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
              Storyboard.TargetProperty="(Panel.Background). 
       (SolidColorBrush.Color)"> 
             <EasingColorKeyFrame KeyTime="0" 
            Value="#FFF34235" /> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <ContentPresenter /> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Style.Triggers> 
     <Trigger Property="IsSelected" Value="True" > 
      <!--<Setter Property="ContentTemplate" Value="{StaticResource DT_TestTemplateSelectedItem}" />--> 
      <Setter Property="BorderBrush" Value="Transparent" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

내가 그것을 마우스 휠을 스크롤 할 수 있도록해야합니까?

+0

명확하지 않기 때문에 질문을 명확히하십시오. – Aybe

답변

0

ScrollViewer를 내 목록 상자의 부모 컨테이너로 사용하고 코드 뒤에 PreviewMouseWheel 이벤트를 처리했습니다.

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel"> 
    <ListBox ItemContainerStyle="{StaticResource ResourceKey=ContainerStyle}" Background="{StaticResource StaticBackground}" ItemsSource="{Binding ListSource}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel Orientation="Vertical" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type ListBox}, Mode=FindAncestor}}" ScrollViewer.VerticalScrollBarVisibility="Disabled"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
    </ListBox> 
</ScrollViewer> 

여기 내 코드가 있습니다.

private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) 
{ 
    ScrollViewer viewer = sender as ScrollViewer; 
    viewer.ScrollToHorizontalOffset(viewer.HorizontalOffset - e.Delta); 
} 

발견 된이 post이 발견되었습니다.