none
ISupportIncrementalLoading and binding

    Question

  • Hi,

    I am using a gridview defined like this to display the results of a search (root datacontext is a IObservableMap<String, Object> DefaultViewModel:

    <common:LayoutAwarePage
        x:Name="pageRoot"
        x:Class="MyCompany.EbookReader.Views.SearchPage"
        DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
        IsTabStop="false"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyCompany.EbookReader.Views"
        xmlns:data="using:MyCompany.EbookReader.Data"
        xmlns:common="using:MyCompany.EbookReader.Common"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
      
    <Grid DataContext="{Binding Item}"
            Style="{StaticResource LayoutRootStyle}">
    
      <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
    
      <!-- Back button and page title -->
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
        <TextBlock x:Name="pageTitle" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}" Grid.Column="1"/>
      </Grid>
    
      <GridView Margin="117,0,0,0" x:Name="GrdSearch" Grid.Row="1"
                ItemClick="GridView_ItemClick_1"
                DataFetchSize="1.5"
                IncrementalLoadingThreshold="1"
                ItemsSource="{Binding Search, Mode=TwoWay}"
                ItemsPanel="{StaticResource itemTemplateHorizontal}"
                ItemTemplate="{StaticResource BookDetailItemTemplate}"
                SelectionMode="None" IsItemClickEnabled="True"
                Style="{StaticResource HorizontalStyle_GridView}">
       
        <GridView.Header>
          <TextBlock x:Uid="SearchHeader"  Margin="0,0,0,0" Style="{StaticResource SubheaderTextStyle}" />
        </GridView.Header>
        <GridView.ItemContainerStyle>
          <Style TargetType="FrameworkElement">
            <Setter Property="Margin" Value="0,0,0,25"/>
          </Style>
        </GridView.ItemContainerStyle>
       
      </GridView>
    </Grid>
    </common:LayoutAwarePage>


    And ItemsSource is binded to Search a custom generic ObservableCollection called IncrementalLoadingCollection<T> and implementing ISupportIncrementalLoading.

    Generally when gridview is displayed it calls the interface method LoadMoreItemsAsync and it works fine the first time.

    However I have a problem when I want to do another search because I receive an event to indicate search term has changed and I am doing this :

    void BookItemFetcher_SearchChanged(object sender, string e) { StoreDataItem item = ReaderDataSource.Source.CurrentLib; if (item != null) {

    // Clear list and reset the HasMoreItems VAriable item.Search.Reset(); //item.InitSearch(); this.DefaultViewModel["Item"] = item; } }


    with Search the IncrementalCollection defined like this :

    public IncrementalBookDataItemCollection Search
            {
                get { return this._Search; }
                set { this.SetProperty(ref this._Search, value); }
            }


    and Reset the following method :

    public void Reset()
            {
                _hasMoreItems = true;
                this.Clear();
                
            }

    but display is not refreshed. I have also tried to reinstantiate the Search collection but it doesn't work either.

    Dont really know what to try next ...

    So my question is : how can I tell the GridView to start again to fetch items from the IncrementalLoadingCollection ?


    Friday, January 04, 2013 4:44 PM

Answers

  • Ok I found the answer on another post :

    I already forgot the most important part ;) You can workaround the issue when rebinding the ListView's ItemsSource property. All you have to do is to invoke LoadMoreItemsAsync( 1 ) manually. 

    • Marked as answer by Vincent Rich Monday, January 07, 2013 4:19 PM
    Monday, January 07, 2013 4:19 PM