Todd Main
Todd Main

Reputation: 29153

Strange Binding Issue with FlipView and TextBox

I'm having a huge issue with FlipView and binding. I have a FlipView with a TextBox on each item. When I enter text in the TextBox, and then flip to the next item, the TextBox.Text value is empty. So is the next one. But on the fourth item (Index=3), it displays the text that I typed on Index=0. This continues on to not display on the fifth and sixth items, but again appears on the seventh item (Index=6).

So if on Index=0 I typed Test in the TextBox, I see Test on the fourth and seventh slides (indexes 3 and 6). This can continue on forever.

To compound the problem, it follows the last entered text and then displays that on multiple of 3. So, if I now go to the second item (Index=1) and type Test2, it will appear on Index=4 and Index=7.

I've tried this across multiple projects and the result is the same. I don't have another computer in which to try it on. The results are the same across running it in the simulator, local machine and remote machine.

Here's what it looks like: binding error issue in flipview

For me, it really simple to recreate. Just add a BasicPage and then to that page in the grid add:

<FlipView Grid.Column="1" Grid.Row="1" Margin="100,0,50,0" x:Name="TabFlipView">
    <FlipView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBox  Width="400" Height="100" VerticalContentAlignment="Bottom"  />
                <TextBlock Text="{Binding}"/>
            </StackPanel>
        </DataTemplate>
    </FlipView.ItemTemplate>
</FlipView>

In the LoadState, add:

Dim d As New ObservableCollection(Of String) From {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
        TabFlipView.ItemsSource = d

Then run it. In the first TextBox type some text. Flip to the 4th item. The text that you just typed in the first item is there in the TextBox on the fourth item.

If this is somehow machine-specific and you can't reproduce, how would I go about troubleshooting this to find and eliminate the cause?

Upvotes: 1

Views: 462

Answers (1)

NakedBrunch
NakedBrunch

Reputation: 49413

Try putting

VirtualizingStackPanel.VirtualizationMode = "Standard"` 

in your FlipView. This should stop the recycling.

See this MSDN link for more information:

Update based off of comments

If you can avoid the VirtualizingStackPanel, the following may work for you:

<FlipView.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"></StackPanel>
     </ItemsPanelTemplate>
</FlipView.ItemsPanel>

Upvotes: 2

Related Questions