滚动嵌套列表框wpf

时间:2011-07-24 15:16:21

标签: wpf xaml listbox scroll

一些背景: 我们正在尝试使用一些自定义功能构建一个类似outlook的调度控件。 我已经完成了代码项目中的类似帖子,但我们倾向于采用稍微不同的方法(尝试使用MVVM方法)。

问题: 目前我们有一个包含3个项目的列表框。列表框中的每个项目都是另一个列表框,边框为项目。例如XAML代码看起来像这样

<ListBox Name="MasterListBox" HorizontalAlignment="Stretch" Height="500" Width="500">
              <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBoxItem >
            <ListBox Name="Child1" Height="240">
                <ListBoxItem>
                    <Border Width="200" Background="Red" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200" Background="Blue" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200"  Background="Green" Height="40"></Border>
                </ListBoxItem>
            </ListBox>
        </ListBoxItem>
        <ListBoxItem >
            <ListBox Name="Child2" Height="240">
                <ListBoxItem >
                    <Border Width="200" Background="Yellow" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200" Background="Green" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200"  Background="Pink" Height="40"></Border>
                </ListBoxItem>
            </ListBox>
        </ListBoxItem>
        <ListBoxItem >
            <ListBox Name="Child3" Height="240">
                <ListBoxItem >
                    <Border Width="200" Background="Aqua" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200" Background="Beige" Height="40"></Border>
                </ListBoxItem>
                <ListBoxItem >
                    <Border Width="200"  Background="Brown" Height="40"></Border>
                </ListBoxItem>
            </ListBox>
        </ListBoxItem>
</ListBox>

问题是当我点击白色区域中MasterListBox的第一个项目(Child1)并向右拖动时,MasterListBox列表框滚动到右边,但是当我点击子项目时(例如说红色边框)和向右拖动MasterListBox不向右滚动。 我知道我正在尝试拖动内部列表框的项目,这就是外部列表框不滚动的原因,但它有一种方法可以覆盖它。我也想选择内部项目,因此不能为内部项目设置IsHitTestVisible =“False”。

感谢您对此进行调查。非常感谢您的帮助。

问候
SAURABH

1 个答案:

答案 0 :(得分:0)

执行此操作的一种方法是使用内部ListBox的{​​{1}},OnPreviewLeftMouseDownOnPreviewMouseMove事件创建拖动到滚动功能,以实现期望的效果。

另一种方法是找到负责内部OnPreviewMouseUp内的拖动滚动功能的事件,并覆盖事件处理程序,以便将事件路由到外部ListBox