Question

I have a FlipView which shows images. I want the user to be able to select if he wants to view one or two images at a time. Can this be done with a single collection or will I need to have two different collections for the two modes?

What I have now for a single image is a collection called PageCollection that contains a class called Page that has the property Image.

<FlipView x:Name="flipView" ItemsSource="{Binding PageCollection}">
  <FlipView.ItemTemplate>
    <DataTemplate>          
        <Image Source="{Binding Image, Converter={StaticResource ImageConverter}}"/>
    </DataTemplate>
  </FlipView.ItemTemplate>
</FlipView>

The way I think I could solve it is to have another collection that keeps a class like Pages that has two image properties instead of just one. Like this:

<FlipView x:Name="flipView" ItemsSource="{Binding PageCollection2}">
  <FlipView.ItemTemplate>
    <DataTemplate>
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Image Source="{Binding Image1, Converter={StaticResource ImageConverter}}"/>
        <Image Source="{Binding Image2, Converter={StaticResource ImageConverter}}"/>
      </Grid>
    </DataTemplate>
  </FlipView.ItemTemplate>
</FlipView>

Then switch the ItemsSource and DataTemplate when needed. But this doesn't feel like the right way to do it, since keeping the two collections synced seems like a hassle. Is it possible to solve this with a single collection or in some other more efficient way?

Was it helpful?

Solution

As far as I know, there is no simpler way than the one you described.

But the synching is not so difficult: just have a CurrentIndex and a DoublePageCurrentIndex property on your view model. Bind these to the SelectedIndex property of the flipviews and keep them synchronized through their setters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top