我有全景控件的項目模板。在那個模板中,我有listItem模板的列表框。我在列表框中選擇已更改的事件有問題。針對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元素完美的作品。
問題: 1.當我從一個全景項目頁面的列表中選擇新項目時,它將觸發,相同的選擇會更改所有全景項目的事件。
例如: 讓我們考慮一下,我有4個全景項目。我從第一個全景項目列表框中選擇第二個項目。這個選擇改變了4次執行的事件。
我的期望是,當我從列表中選擇新項目時,此事件應該只觸發一次相應的全景項目。
PLS建議我,該怎麼辦呢?
確實每個全景控制和每個列表框都有分配給他們的唯一selectionshanged事件? – earthling 2012-02-29 22:29:40