Set SelectedIndex ListView in FlipView_SelectionChanged Event

I am creating a Photos application using FlipView. In the BottomAppBar, I placed ListViewall the images in order to be able to view the image in FlipViewwhen I click it in ListViewand get the image displayed in the FlipViewone selected in ListView(e.g. pagination).

In the event, listView.selectionChangedI made code that displays the image in FlipView, when I select it in ListView. Here is the code:

    private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();
            int IndicatorIndex = listView.SelectedIndex;

            GoToPage(CurrentViewState, IndicatorIndex);
        }

    private void GoToPage(string CurrentViewState, int IndicatorIndex)
        {
            if (CurrentViewState == "Portrait") 
            {
                flipView1.SelectedIndex = IndicatorIndex;
            }
            else if (CurrentViewState == "Landscape")
            {
                if (IndicatorIndex % 2 == 0)
                    flipView1.SelectedIndex = IndicatorIndex / 2;
                else
                {
                    if (IndicatorIndex == 1)
                        flipView1.SelectedIndex = 1;
                    else
                        flipView1.SelectedIndex = (IndicatorIndex + 1) / 2;
                }
            }
        } 

Now that I need to change listView.SelectedIndexaccording toflipView.SelectedIndex

listView.SelectedIndex = flipView.SelectedIndex

I have an exception:

An exception of type 'System.ArgumentException' occurred in eBookApp.exe but was not handled in user code. Additional information: Value does not fall within the expected range.

I need to get the same image selected in FlipView, selected and scrollable in ListView...

+1
2

, FlipView:

SelectedIndex="{Binding Path=SelectedIndex, ElementName=listView1, Mode=TwoWay}"

ListView:

SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"

SelectedIndex !

+1

Change Change SelectedIndex.

<Page
    x:Class="BlankApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel Margin="100, 100, 0, 0">
            <FlipView x:Name="flipView1" Width="500" Height="200" SelectionChanged="flipView1_SelectionChanged">
                <Image Source="Assets/Logo.scale-100.png" />
                <Image Source="Assets/SmallLogo.scale-100.png" />
                <Image Source="Assets/SplashScreen.scale-100.png" />
            </FlipView>
            <ListView Name="listview1" SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"></ListView>
            <TextBlock Text="{Binding Path=SelectedIndex, ElementName=flipView1}" />
        </StackPanel>
    </Grid>
</Page>
0

All Articles