ListBox 内的 ListBox 和 selectedItem/Events [英] ListBox inside ListBox and selectedItem / Events

查看:24
本文介绍了ListBox 内的 ListBox 和 selectedItem/Events的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在被困在这个问题上有一段时间了,所以我想问问这里的专家.

I have now been stuck at this for some time so I though to ask the experts here.

首先是 XAML:

<ListBox Grid.Column="0" Tap="Some_Tap" SelectionChanged="Some_SelectionChanged">

                    <ListBox.ItemTemplate>
                        <DataTemplate>

                            <!-- the panel which covers a complete list item -->
                            <StackPanel Orientation="Vertical">

                                <!-- start and end time for the travel route-->
                                <Grid HorizontalAlignment="Center">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100"/>
                                        <ColumnDefinition Width="100"/>
                                        <ColumnDefinition Width="100"/>
                                        <ColumnDefinition Width="100"/>
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>


                                    <!-- some textblock items, removed to keep this simple -->
                                </Grid>

                                <!-- list box for images -->
                                <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"  ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding Thumbs}" HorizontalAlignment="Center" Margin="0,10,0,50">
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" />
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>

                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Vertical" HorizontalAlignment="Center">

                                                <Image Source="{Binding Image}" HorizontalAlignment="Center"/>
                                                <TextBlock Text="{Binding Text}" HorizontalAlignment="Center" FontWeight="{Binding FontWeightForText}">
                                                    <TextBlock.Foreground>
                                                        <SolidColorBrush Color="{StaticResource PhoneForegroundColor}"/>
                                                    </TextBlock.Foreground>
                                                </TextBlock>

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

                                </ListBox>

                            </StackPanel>
                        </DataTemplate>

                    </ListBox.ItemTemplate>

                </ListBox>

正如您从 XAML 中看到的,我在另一个 ListBox 的数据模板内有一个 ListBox.我有 Tap &SelectionChanged 事件已连接.

So as you can see from the XAML I have a ListBox inside the data template of another ListBox. I have Tap & SelectionChanged events wired.

问题:

  1. 我无法点击内部列表框覆盖的区域,外部列表框的点击或选择更改事件不会为外部列表框触发.

  1. I can't click on the area covered by the inner list box, the tap or selection changed events for the outer list box are not fired for the outerlistbox.

我也可以为内部列表框连接点击和选择更改事件,但是我怎么知道这个内部列表框属于外部列表框中的哪个项目,selectedindex.

I could wire tap and selection changed events for the inner listbox as well, but then how would I know which item in the outerlistbox this innerlistbox belongs to, selectedindex.

帮助??

-A

推荐答案

如果不需要列表中的项目选择,请使用 ItemsControl 代替(这种情况下的内部列表)

If you don't need items selection in the list, use ItemsControl instead (for inner list in this situation)

这篇关于ListBox 内的 ListBox 和 selectedItem/Events的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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