albilaga
albilaga

Reputation: 439

Flipview not update SelectedItem

I have FlipView like this

<FlipView Grid.Row="1" Grid.RowSpan="2" HorizontalContentAlignment="Center" x:Name="BookPageContentFlipView" ItemsSource="{Binding BookPagesNew,Mode=OneWay}"
                  SelectedItem="{Binding SelectedPage,Mode=TwoWay}"
                  SelectionChanged="BookPageContentFlipViewSelectionChanged" >
            <FlipView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Background="Transparent" Orientation="Horizontal"
                                            VirtualizationMode="Recycling" AreScrollSnapPointsRegular="True" />
                </ItemsPanelTemplate>
            </FlipView.ItemsPanel>
            <FlipView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Center" Width="650" x:Name="GridWebView">
                        <WebView
                            common:HTMLStringExtension.HTML="{Binding HTMLString}" 
                            ScriptNotify="OnBookPageContentWebViewScriptNotify"
                            Tapped="OnBookPageContentFlipViewTapped" />
                        <Image Source="ms-appx:///Assets/add-bookmark.png" x:Name="BookmarkImage"
                               Tapped="OnBookmarkImageTapped" HorizontalAlignment="Right" VerticalAlignment="Top"
                               Width="38"
                               Height="38" />
                    </Grid>
                </DataTemplate>
            </FlipView.ItemTemplate>

        </FlipView>

I am using MVVM and update this flipview ItemsSource from VM. Now my problem is when I am update ItemsSource from VM and use NotifyPropertyChanged() to notify View to update the flipview ItemsSource, my selected flipview not updating the view with new data.

But after I move about > 2 item (next/previous) item the view correctly updated. How I can force my flipview to update the currently selected item without need to reload flipview?

Upvotes: 2

Views: 498

Answers (1)

frenk91
frenk91

Reputation: 929

I think that BookPagesNew needs to implement the interface INotifyPropertyChanged because if you change only one property of an item in a list the view doesn't get the notification.

you can use this code to implement the interface

public class BookPagesNew : INotifyPropertyChanged
{
    public string HTMLString { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

in your VM BookPagesNew should be an ObservableCollection<BookPagesNew>

Upvotes: 2

Related Questions