嵌套ListViews和MouseWheel事件 [英] Nested ListViews and the MouseWheel Event

查看:60
本文介绍了嵌套ListViews和MouseWheel事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个具有一堆垂直排列的ListView的页面,我可以使用StackPanel做到这一点,但是我需要一个ItemsControl来将项目列表绑定到,因此我使用了ListView来包含ListViews列表.问题是,当鼠标悬停在内部ListView之一上时,MouseWheel事件不会像我期望的那样冒泡到外部Listview.这是一些在XAMLPad中工作的示例代码.外部listview是我希望能够滚动的视图.内部的将始终为全高,因此它们将不需要垂直滚动,而是希望让MouseWheel事件冒泡.我该怎么做呢?

I am trying to make a page that has a bunch of ListViews arranged vertically, I could do this with a StackPanel, but I needed an ItemsControl to bind the list of items to, so I used a ListView to contain a list of ListViews.  The problem is that when the mouse is over one of the inner ListViews the MouseWheel event doesn't bubble up to the outer listview as I would expect.  Here's some sample code that works in XAMLPad. The outer listview is the one I want to be able to scroll.  The inner ones will always be full height so they will never need to scroll vertically, instead I want the MouseWheel event to bubble.  How do I go about doing this?

< Page xmlns =< xmlns:x =""< ListView.Items>
< TextBlock Text =''A''; />
.< TextBlock Text ="B"; />
.< TextBlock Text ="C"; />
</ListView.Items>
</ListView>
</Expander>
</DataTemplate>

</ListView> < ListView.Items>
< TextBlock Text =" A" />
.< TextBlock Text ="B"; />
.< TextBlock Text ="C"; />
.< TextBlock Text ="D"; />
.< TextBlock Text ="E"; />
.< TextBlock Text ="F"; />
.< TextBlock Text ="G"; />
.< TextBlock Text ="H"; />
.< TextBlock Text ="I" />
.< TextBlock Text ="J"; />
.< TextBlock Text ="K"; />
</ListView.Items>
</ListView>
</Page>

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      WindowTitle="ScrollViewer Sample">
        <ListView ScrollViewer.CanContentScroll="False">
          <ListView.ItemTemplate>
            <DataTemplate>
  <Expander IsExpanded="True">
   <Expander.Header>
    <TextBlock Text="{Binding Text}" />
   </Expander.Header>
   <ListView Height="Auto" ScrollViewer.CanContentScroll="False">
     <ListView.Items>
      <TextBlock Text="A" />
      <TextBlock Text="B" />
      <TextBlock Text="C" />
     </ListView.Items>
   </ListView>
  </Expander>
            </DataTemplate>
          </ListView.ItemTemplate>
 <ListView.Items>
  <TextBlock Text="A" />
  <TextBlock Text="B" />
  <TextBlock Text="C" />
  <TextBlock Text="D" />
  <TextBlock Text="E" />
  <TextBlock Text="F" />
  <TextBlock Text="G" />
  <TextBlock Text="H" />
  <TextBlock Text="I" />
  <TextBlock Text="J" />
  <TextBlock Text="K" />
 </ListView.Items>
        </ListView>
</Page>

推荐答案

问题可能是第一个接收到鼠标滚轮消息的ListView在事件args上设置了e.Handled = true.这样可以防止路由事件冒泡到包含ListView的事件.在这种情况下,您可以为外部ListView调用AddHandler(以附加事件处理方法),并在参数列表中指示无论是否已处理事件都应调用您的处理程序.
The problem might be that the first ListView which receives the mouse wheel messages is setting e.Handled = true on the event args.  That would prevent the routed event from bubbling up to the containing ListView.  If that is the case, you can call AddHandler for the outer ListView (to attach the event handling method) and, in the argument list, indicate that your handler should be invoked whether the event was handled or not.


这篇关于嵌套ListViews和MouseWheel事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆