我現在已經堅持了一段時間,所以我雖然要問這裏的專家。列表框內ListBox和selectedItem /事件
首先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看到我還有一個列表框的數據模板中的列表框。我有TapSelectionChanged事件有線。
問題:
我不能由內部列表框覆蓋的區域點擊,輕敲或選擇改變事件外列表框,不會引發了outerlistbox。
我可以連接內部列表框的tap和selection changed事件,但是我怎麼知道這個innerlistbox屬於的outerlistbox中的哪個項目selectedindex。
help?
-A
通過稍微改變了XAML解決,不C#代碼被更改XAML。內部列表框已更改爲ItemsControl,如下面的Ku6opr回答。 – 2012-03-29 08:07:53