在嵌套列表框wpf中滚动
一些背景: 我们正在尝试构建一个类似 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" 。
感谢您对此进行调查。非常感谢您的帮助。
问候
索拉布
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 items. For E.g. the XAML code looks like this
<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>
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用内部
ListBox
的OnPreviewLeftMouseDown
、OnPreviewMouseMove
和创建拖动滚动功能OnPreviewMouseUp
事件来实现想要的效果。另一种方法是在内部
ListBox
中查找负责拖动滚动功能的事件,并重写事件处理程序,以便将事件路由到外部ListBox< /代码>。
One way to do this would be to create drag-to-scroll functionality using the inner
ListBox
'sOnPreviewLeftMouseDown
,OnPreviewMouseMove
, andOnPreviewMouseUp
events to implement the desired effect.Another way is to find the event(s) responsible for the drag-to-scroll functionality within the inner
ListBox
and to override the event handler so that the event gets routed to the outerListBox
.