我的列表视图包含近10项。我可以为列表视图显示垂直滚动 栏。我可以通过单击垂直滚动条来滚动项目
但我想要的是当用户控制列表视图并尝试滚动项目 鼠标时我无法做到。
请帮助我如何解决这个问题。
请给我你宝贵的建议。
我在这里添加我的列表查看代码
<Border BorderThickness="0.5" CornerRadius="2" BorderBrush="Gray" Width="1250" Height="730" Margin="0,5,0,0">
<StackPanel Name="spStore" Visibility="Hidden" Background="AliceBlue">
<Label Content="{DynamicResource keyStore Management}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="DarkTurquoise"/>
<!--Scroll view to display list of items-->
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="690" Visibility="Visible">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="{DynamicResource keySTOCK MANAGEMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="0"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="1" ScrollViewer.CanContentScroll="True" Name="lvstock" PreviewMouseWheel="lvstock_PreviewMouseWheel">
<ListViewItem MouseLeftButtonUp="StockDetails_Click" Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Critical.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyView Stocks}" ></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockVerificationDetails_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerify Stocks}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="VerifiedStockDetails_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerified Stock Report}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyGOODS TRANSFER}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="2"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="3">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockReceipt_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Receipt}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockIssue_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsIssue.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Issue}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" Name="GoodsReturn" BorderThickness="0.5,0.5,0.5,0" MouseLeftButtonUp="GoodsReturn_MouseLeftButtonUp" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyGoodsReturn}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyGOODS PROCUREMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="4"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="5">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/PO.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyPurchases}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="ProcurementReceipt_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyReceipts}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyDELIVERIES}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="6"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="7">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/NewOrder.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyOrders}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyShipments}">Shipments</TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Border>
提前致谢。
答案 0 :(得分:0)
您应该更改DragOver
的{{1}}事件,如下所示:
ListView
答案 1 :(得分:0)
您的XAML代码的主要问题是MouseWheel事件由主ScrollViewer内的每个内部ListView处理。
如果内部ListView具有内部滚动条(防止双滚动 - 滚动内滚动条和滚动外滚动条),这是正确的行为。
由于滚动不适用于内部ListView,您可以为每个内部ListView分配特殊的不可滚动模板,如以下示例所示:
在资源中定义ListView的模板:
<Window.Resources>
<ControlTemplate x:Key="NonScrollableListView" TargetType="ListView">
<ItemsPresenter/>
</ControlTemplate>
</Window.Resources>
然后将它用于主ScrollViewier中的每个ListView:
<ScrollViewer>
<StackPanel Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<!--...-->
</Grid.RowDefinitions>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="1" Name="lvstock">
<!--...-->
</ListView>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="3">
<!--...-->
</ListView>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="5">
<!--...-->
</ListView>
</Grid>
</StackPanel>
</ScrollViewer>
答案 2 :(得分:0)
在尝试了很多例子后,我找到了解决方案并且它对我来说很好。我观察到的内部堆栈面板滚动不起作用,但在Grid工作,而不是采取多个列表视图我只使用单一列表视图。谢谢大家提出宝贵的建议。
我在这里放置我的工作代码...再次感谢你们的建议。
<Grid Name="spStore" Visibility="Hidden" Background="AliceBlue">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="{DynamicResource keyStore Management}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Grid.Row="0" Foreground="DarkTurquoise"/>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="1" Name="lvstock">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keySTOCK MANAGEMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem MouseLeftButtonUp="StockDetails_Click" Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Critical.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyView Stocks}" ></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockVerificationDetails_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerify Stocks}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="VerifiedStockDetails_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerified Stock Report}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyGOODS TRANSFER}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockReceipt_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Receipt}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockIssue_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsIssue.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Issue}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" Name="GoodsReturn" BorderThickness="0.5,0.5,0.5,0" MouseLeftButtonUp="GoodsReturn_MouseLeftButtonUp" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyGoodsReturn}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyGOODS PROCUREMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/PO.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyPurchases}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="ProcurementReceipt_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyReceipts}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyDELIVERIES}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/NewOrder.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyOrders}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyShipments}">Shipments</TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
答案 3 :(得分:0)
ScrollViewer中的ListView对我不起作用,它有助于删除ScrollViewer并设置ListView的scrollviewer.verticalscrollbarvisibility = true属性