2012-02-29 2 views
1

파노라마 컨트롤에 대한 항목 템플릿이 있습니다. 이 템플릿에는 listItem 템플릿이있는 listbox가 있습니다. 목록 상자에서 선택 변경 이벤트에 문제가 있습니다.Windows Phone 용 panorama.ItemTemplate의 ListBox에 대한 SelectionChanged 이벤트?

<phone:PhoneApplicationPage.Resources> 
    <CollectionViewSource x:Key="SlideItemList" Filter="collectionView_Filter"/> 
</phone:PhoneApplicationPage.Resources> 

<!--LayoutRoot is the root grid where all page content is placed--> 
<Grid x:Name="LayoutRoot" Background="Transparent"> 

    <!--Panorama control--> 
    <controls:Panorama x:Name="AppPano" ItemsSource="{Binding SlidesCollections}" SelectionChanged="AppPano_SelectionChanged" > 
     <controls:Panorama.Background> 
      <ImageBrush ImageSource="PanoramaBackground.png"/> 
     </controls:Panorama.Background> 

     <controls:Panorama.ItemTemplate> 
      <DataTemplate> 
       <Grid VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,-100,0,0"> 
        <StackPanel HorizontalAlignment="Center" Height="250" Width="200" VerticalAlignment="Top"> 
         <TextBlock Text="{Binding Title}" HorizontalAlignment="Center" FontSize="200" Width="Auto"/> 
        </StackPanel> 
        <ListBox x:Name="ItemsList" ItemsSource="{Binding Source={StaticResource SlideItemList}}" Margin="0,250,0,0" VerticalAlignment="Top" SelectionChanged="ItemsList_SelectionChanged" Height="430"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <StackPanel x:Name="ImgStack" HorizontalAlignment="Left" Height="430" VerticalAlignment="Top" Width="370" Margin="50,0,0,0"> 
            <Image Height="350" Width="360" Source="{Binding Image}"/> 
            </StackPanel> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
       </Grid> 
      </DataTemplate> 
     </controls:Panorama.ItemTemplate> 
    </controls:Panorama> 
</Grid> 

Xaml.cs

private void keyItemsList_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     var listbox = (ListBox)sender; 
     var conGen = listbox.ItemContainerGenerator; 
     var item = (UIElement)conGen.ContainerFromIndex(listbox.SelectedIndex); 

     if (item != null) 
     { 
      int selectedItemList = listbox.SelectedIndex; 
      if (sLasListItem != selectedItemList) 
      { 
       // navigate to another page 
       sLasListItem = selectedItemList; 
      } 
     } 
    } 

바인딩 UI 요소가 완벽하게 작동합니다.

문제점 : 하나의 파노라마 항목 페이지의 목록에서 새 항목을 선택하면 해당 항목이 모든 파노라마 항목에 대해 동일한 선택 변경 이벤트를 발생시킵니다.

예 : 4 가지 파노라마 항목이 있습니다. 첫 번째 파노라마 항목 목록 상자에서 두 번째 항목을 선택했습니다. 이 선택 변경 이벤트가 4 번 실행되었습니다.

목록에서 새 항목을 선택하면 해당 파노라마 항목에 대해 한 번만이 이벤트가 실행됩니다. 같은 목록 4 번을 결합하고 있기 때문에

Pls는 저를 제안, 그것을 어떻게 ...

+0

각 파노라마 컨트롤과 각 목록 상자에는 고유 한 선택 이벤트가 할당되어 있습니까? – earthling

답변

1

이 있습니다. (SlidesCollections에는 4 개의 항목이 포함되어 있다고 가정합니다.)

각 목록은 동일한 데이터이므로 선택한 항목을 한 번보기로 변경하면 기본 (필터링 됨에도 불구하고) 목록에서 실제로 변경됩니다.

대신보기 모델에서 별도의 목록을 만들어야합니다.

+0

정말 고마워요! 심지어 같은 문제가 있었고 답을 기반으로 해결할 수있었습니다! @ 저자 : 해결 답변으로 표시하시기 바랍니다 –

관련 문제