2012-03-28 63 views
0

我現在已經堅持了一段時間,所以我雖然要問這裏的專家。列表框內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事件有線。

問題:

  1. 我不能由內部列表框覆蓋的區域點擊,輕敲或選擇改變事件外列表框,不會引發了outerlistbox。

  2. 我可以連接內部列表框的tap和selection changed事件,但是我怎麼知道這個innerlistbox屬於的outerlistbox中的哪個項目selectedindex。

help?

-A

+0

通過稍微改變了XAML解決,不C#代碼被更改XAML。內部列表框已更改爲ItemsControl,如下面的Ku6opr回答。 – 2012-03-29 08:07:53

回答

1

如果你不需要的物品選擇列表中的,(在這種情況下對內部列表)使用ItemsControl代替

+0

所以這工作得很好,但我仍然懷疑。我只是將內部ListBox更改爲ItemsControl(更改了XAML中的標籤),然後工作。 – 2012-03-29 08:02:47

0

只需設定內部ListBox控件IsEnabled = false和外部的點擊事件將開始執行!

+0

我可以這樣做,但因爲ListBox具有用於禁用模式的不同模板,所以列表框看起來很醜。如果我使用此解決方案,則需要爲禁用模式定義新樣式。 – 2012-03-28 10:59:48

+0

是的,但您可以繼續,只需編輯ListBox模板並刪除禁用狀態的視覺狀態! :) – 2012-03-28 13:23:22