1

我正在使用FlipView. 在 BottomAppBar 中,我放置了所有图像中的一个,以便当我在 中单击它时ListView能够查看图像,并在 中选择显示的图像(如分页)。FlipViewListViewFlipViewListView

listView.selectionChanged事件中,FlipView当我在ListView. 这是代码:

    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;
                }
            }
        } 

现在当我需要listView.SelectedIndex根据flipView.SelectedIndex

listView.SelectedIndex = flipView.SelectedIndex

我有一个例外:

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.

我需要能够在FlipView, selected 和 scrollAt 中选择相同的图像ListView...

4

2 回答 2

1

我最终通过添加到我的FlipView

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

和我的ListView

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

他们两个SelectedIndex互相指代!

于 2015-04-21T11:43:11.887 回答
0

除了选择更改事件,更简单的方法是使用数据绑定到 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>
于 2015-04-21T01:41:09.517 回答