首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows Phone的panorama.ItemTemplate中的ListBox的SelectionChanged事件?

在Windows Phone的panorama.ItemTemplate中的ListBox的SelectionChanged事件?
EN

Stack Overflow用户
提问于 2012-02-29 22:31:30
回答 1查看 1.6K关注 0票数 1

我有全景控件的项目模板。在该模板中,我有带有listItem模板列表框。我在列表框中选择已更改的事件时遇到问题。

代码语言:javascript
复制
<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

代码语言:javascript
复制
  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次。

我的预期是,当我从列表中选择新项目时,此事件应该只为相应的全景项目触发一次。

请建议我,怎么做……

EN

回答 1

Stack Overflow用户

发布于 2012-03-01 09:02:26

这是因为你绑定了同一个列表4次。(假设SlidesCollections包含4个项目。)

因为每个列表都是相同的数据,所以当您在该数据的一个视图中更改所选项目时,它实际上是在底层(尽管经过过滤)列表中更改的。

您应该改为在视图模型中创建单独的列表。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9500934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档