简体   繁体   English

如何防止内部ListBox在嵌套的ListBox中滚动? (WP8)

[英]How to prevent the inner ListBox's scrolling in nested ListBoxes? (WP8)

I have nested ListBoxes: 我嵌套了ListBoxes:

<ListBox Name="listbox" Padding="0,0,0,100" Loaded="listbox_Loaded" Foreground="Black">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Name}" FontSize="30" FontWeight="Bold"/>
                <ListBox ItemsSource="{Binding Categories}" Foreground="Black">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>

                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

When I touch and drag items from inner listbox it plays scroll animation for this inner listbox. 当我触摸并从内部列表框中拖动项目时,它将为此内部列表框播放滚动动画。 How to prevent this behavior? 如何预防这种行为? I need to scroll the outer listbox only, but the items from inner listbox still must be selectable. 我只需要滚动外部列表框,但是内部列表框中的项目仍然必须是可选择的。

Thank you! 谢谢!

Try to change Template of inner ListBox to be only ItemsPresenter . 尝试将内部ListBox Template更改为仅ItemsPresenter This will remove ScrollViewer which is normally part of that template: 这将删除ScrollViewer ,它通常是该模板的一部分:

<ListBox ItemsSource="{Binding Categories}" Foreground="Black">
    <ListBox.Template>
        <ControlTemplate TargetType="ListBox">
            <ItemsPresenter/>
        </ControlTemplate>
    </ListBox.Template>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM