在嵌套的列表框WPF中滚动 [英] Scrolling in nested Listbox wpf

查看:87
本文介绍了在嵌套的列表框WPF中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends

希望大家都做的很好.

我对WPF列表框有一些疑问

某些背景:

我们正在尝试使用一些自定义功能来构建诸如Outlook之类的调度控件.
我已经看过Code Project中的类似文章,但我们倾向于采用略有不同的方法(尝试使用MVVM方法).

问题:
目前,我们有一个包含3个项目的列表框.列表框中的每个项目都是另一个带有边框作为子项目的列表框.对于XAML代码如下所示.

Hi Friends

Hope you all are doing good.

I have few questions about WPF List BOX

Some Background:

We are trying to build a scheduling control like outlook with some custom functionality.
I have already gone through the similar post in Code Project but we tend to take slightly different approach (trying to use MVVM approach).

Problem:
Currently we have a Listbox with 3 items. Each item in the list box is another Listbox with borders as sub items. For E.g. the XAML code looks like this.

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



问题是,当我单击白色区域中的MasterListBox的第一个项(Child1)并向右拖动时,MasterListBox列表框向右滚动,但是当我单击子项(例如说红色边框)并向右拖动时MasterListBox无法向右滚动.
我知道我正在尝试拖动内部列表框的项目,这就是外部列表框不滚动的原因,但是有一种我们可以替代此方法的方式.我也想选择内部项目,因此无法为内部项目设置IsHitTestVisible ="False".

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

问候
Saurabh



The problem is when I click on the 1st item(Child1) of the MasterListBox in the white area and drag right, the MasterListBox list box scroll to right, But when I click on the subitem (for e.g. say red border) and drag right the MasterListBox doesn’t scroll right.
I am aware that I am trying to drag the item of the inner list box and that’s the reason the outer list box is not scrolling, But it there a way we can override this. I want to select the inner item also so cannot set IsHitTestVisible="False" for inner item.

Thanks you for looking into this. Your help is greatly appreciated.

Regards
Saurabh

推荐答案

而不是将ListBox控件嵌套在另一个ListBox中,正如您所观察到的,这会使用户体验变得复杂;为什么不使用DatGrid来提供您似乎想要的列数据视图呢?假设要在实际应用程序中以不同的颜色显示边框,则可以重新设置CellStyle的样式,并将BorderBrush绑定到转换后的颜色值.
Rather than nesting ListBox controls within another ListBox which, as you observed, complicates the user experience; why not use a DatGrid which gives you the sort of columnar data view you seem to want? Assuming you want to display borders in different colors in your real-world application, you could restyle the CellStyle and bind a BorderBrush to the converted color value.


这篇关于在嵌套的列表框WPF中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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