2015-04-20 44 views
1

我正在使用FlipView构建一个Photo应用程序。在BottomAppBar中,我放置了所有图像的ListView以便能够在FlipView中查看图像,当我在ListView中单击它时,图像显示在ListView(如分页)中选择的FlipView中。在FlipView_SelectionChanged事件中设置ListView的selectedIndex

listView.selectionChanged事件中,当我在ListView中选择它时,我制作了显示FlipView中图像的代码。下面是代码:

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

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

listView.SelectedIndex = flipView.SelectedIndex 

我有一个异常改变listView.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中选择的相同图像,并将其选中并滚动到ListView ...

+0

请比“例外”更具体。你得到什么异常?什么是异常的确切错误信息?什么是异常堆栈跟踪?请提供可靠地重现问题的[良好,_minimal_,_complete_代码示例](http://stackoverflow.com/help/mcve),以及有关如何使用该代码示例重现问题的明确具体说明。 –

+0

我试着编辑我的问题,我添加了我收到的异常消息和更多的代码,希望这是有帮助的! – yalematta

回答

1

我最终作出加入到我的FlipView它的工作:

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

和我ListView

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

他们都SelectedIndex称对方!

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> 
+0

我尝试在Xaml的ListView中添加'SelectedIndex =“{Binding Path = SelectedIndex,ElementName = flipView1,Mode = TwoWay}”'但它**不起作用!** – yalematta

+0

您是否已将ElementName更改为您的FlipView名称?在我的情况下,它是flipView1。 –

+0

是的,我做了,我删除了我的ListView OnSelectionChanged事件,仍然当我更改FlipView选择,没有项目被选中我的ListView – yalematta

相关问题