2016-11-16 11 views
0

イメージエクスプローラをエクスパンダでビルドする必要がありますが、スクロールに問題があります。 ListBox内にItemsControlがあり、ListBox上にマウスを置くとスクロールが機能しません。ここではxamlです:ItemsControl内のListBoxでWPFスクロールが機能しない

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Grid.Row="1" Background="{DynamicResource LightGrayBackgroundBrush}" > 
    <ItemsControl x:Name="itmsControl" DataContext="{Binding ElementName=_self}" ItemsSource="{Binding ImagesSource}" Margin="15" > 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Grid x:Name="grdIn"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto" MinHeight="25"/> 
         <RowDefinition x:Name="grd1"/> 
        </Grid.RowDefinitions> 

        <Expander Grid.Row="1" IsExpanded="True" BorderThickness="0" Background="White"> 
         <Expander.Header> 
          <Border Background="White" BorderBrush="White" Height="40"> 
           <TextBlock Text="{Binding Date}" Background="White" FontSize="14" Foreground="Gray" FontWeight="Bold" VerticalAlignment="Center" Margin="10,0,0,0"/> 
          </Border> 
         </Expander.Header> 

         <ListBox ItemsSource="{Binding ImageList}" ItemContainerStyle="{DynamicResource ImageListBoxItemStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionMode="Extended" Background="Transparent" SelectionChanged="ListBox_SelectionChanged" PreviewKeyDown="OnKeyDownHandler" MouseDown="ListBox_MouseDown" ScrollViewer.CanContentScroll="False"> 
          <ListBox.ItemTemplate> 
           <DataTemplate> 
            <Image Stretch="UniformToFill" Width="{Binding Width}" Height="{Binding Height}" Source="{Binding Source}" Margin="3" MouseDown="Image_MouseDown"/> 
           </DataTemplate> 
          </ListBox.ItemTemplate> 
          <ListBox.ItemsPanel> 
           <ItemsPanelTemplate> 
            <WrapPanel IsItemsHost="True" Orientation="Horizontal" /> 
           </ItemsPanelTemplate> 
          </ListBox.ItemsPanel> 
         </ListBox> 
        </Expander> 
       </Grid> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 
</ScrollViewer> 

答えて

0

、フォーカスがスクロールビューアのために失われます。 したがって、MouseWheel/PreviewMouseWheelイベントでビューアをスクロールするようにフォーカスを設定することも、以下のように手動でスクロールすることもできます。

myScroll.ScrollToVerticalOffset(myScroll.VerticalOffset + 10); 
+0

Iは、リストボックスにPreviewMouseWheelを追加: プライベートボイドListBox_PreviewMouseWheel(オブジェクト送信者、MouseWheelEventArgs E) {mainScroll.ScrollToVerticalOffset(mainScroll.VerticalOffset - e.Delta)を、 } 作品です、ありがとうMaulik :) –

0

ScrollViewerのみスクロールしますか?では、なぜItemsControl内でListBoxを使用しますか? ListBoxのスクロールをブロックすることを見ています。

ScrollViewer.CanContentScroll="False" 

ListBoxはテンプレート内にScrollViewerを持っています。そして、私はこのScrollViewerが "マウスwhell"イベントを処理し、ルートScrollViewerに到達しないと思います。 ListBoxをItemsControlに置き換えるだけで問題を解決できると思います。これで

0

変更XAML:あなたはリストボックスの画像を選択すると

<ListBox.ItemsPanel> 
           <ItemsPanelTemplate> 
<ScrollViewer> 
            <WrapPanel IsItemsHost="True" Orientation="Horizontal" /> 
</ScrollViewer> 
           </ItemsPanelTemplate> 
          </ListBox.ItemsPanel> 
関連する問題