ListBox inside ListBox and selectedItem / Events

喜你入骨 提交于 2019-12-25 08:24:18

问题


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

First the 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>

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.

Problem:

  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.

  2. 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.

help ??

-A


回答1:


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




回答2:


Just set the inner ListBox control IsEnabled = false and the Tap events of the outer will start to execute!



来源:https://stackoverflow.com/questions/9903594/listbox-inside-listbox-and-selecteditem-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!