2017-02-24 7 views
0

DisabledVerticalOrientationVerticalScrollbarVisibilityセットでListBoxItemsPanelTemplateWrapPanelを使用して、私は水平方向にマウスホイールでの私のコンテンツをスクロールすることはできません。リストボックスwrappanelスクロール垂直方向の向きWPF

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が見つかりました。

関連する問題