1

パノラマ コントロールのアイテム テンプレートがあります。そのテンプレートには、listItem テンプレートを含むリストボックスがあります。リスト ボックスの選択変更イベントに問題があります。

<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. 1 つのパノラマ アイテム ページのリストから新しいアイテムを選択すると、すべてのパノラマ アイテムに対して同じ選択変更イベントが発生します。

例: 考えてみましょう。4 つのパノラマ アイテムがあります。1 番目のパノラマ アイテム リスト ボックスから 2 番目のアイテムを選択しました。この選択により、イベントが 4 回実行されました。

私の期待は、リストから新しいアイテムを選択すると、このイベントは対応するパノラマ アイテムに対して 1 回だけ発生するはずでした。

Plsは私にそれを行う方法を提案します...

4

1 に答える 1

1

これは、同じリストを 4 回バインドしているためです。(4つのアイテムが含まれていると仮定しSlidesCollectionsます。)

各リストは同じデータであるため、そのデータの 1 つのビューで選択した項目を変更すると、実際には基になる (フィルター処理された) リストで変更されます。

代わりに、ビュー モデルで個別のリストを作成するようにしてください。

于 2012-03-01T01:02:26.443 に答える