We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Items cant be rebound if they are already rebound

My list view looks like as below. As you can see my datatemplate has just a label which binds the object item itself. This works perfectly fine when it list is loaded but then I have a button on the page, when I click the button, it makes changes on "Items" object. I am not able to refresh these changes even though I raise property changed event as shown below. It looks like that UI is not refreshing. I am not stepping into my converter "ItemLogInfoConvertor". How can I achieve this?


        <sfListView:SfListView x:Name="listItems"                              
                      RowSpacing="5"
               ItemsSource="{Binding Items}"   SelectionMode="Single"     SelectedItem="{Binding SelectedItem}"
                           SwipeThreshold="250"   SwipeOffset="250"   VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                          ItemSpacing="1"  IsStickyHeader="True" IsStickyFooter="False"   
                   AllowSwiping="True" IsEnabled="True" AllowGroupExpandCollapse="False" AutoFitMode="Height" Loaded="listItems_Loaded">
                <sfListView:SfListView.DataSource>
                    <data:DataSource>
                        <data:DataSource.GroupDescriptors>
                            <data:GroupDescriptor PropertyName="ItemNumber" />
                        </data:DataSource.GroupDescriptors>
                    </data:DataSource>
                </sfListView:SfListView.DataSource>
                <sfListView:SfListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <Grid BackgroundColor="#4CA1FE">
                                    <Label Text="{Binding Key,Converter={StaticResource ItemCountConvertor},ConverterParameter={resx:Translate Item,IsUpper=True}}"
                       FontSize="Small"
                       TextColor="White"
                       HorizontalTextAlignment="Start"
                       VerticalTextAlignment="Center"
                       Margin="20,0,0,0" />
                                </Grid>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </sfListView:SfListView.GroupHeaderTemplate>         

                <sfListView:SfListView.LayoutManager>
                    <sfListView:LinearLayout   />
                </sfListView:SfListView.LayoutManager>
              
                    <OnPlatform x:TypeArguments="x:Double">
                        <OnPlatform.Android>
                            <OnIdiom x:TypeArguments="x:Double" Phone="180" Tablet="150" />
                        </OnPlatform.Android>
                        <OnPlatform.iOS>
                            <OnIdiom x:TypeArguments="x:Double" Phone="180" Tablet="150" />
                        </OnPlatform.iOS>
                        <OnPlatform.WinPhone>
                            <OnIdiom x:TypeArguments="x:Double" Phone="180" Tablet="150" Desktop="200" />
                        </OnPlatform.WinPhone>
                    </OnPlatform>
                </sfListView:SfListView.ItemSize>-->
                <sfListView:SfListView.ItemTemplate>
                    <DataTemplate>
 
                            <Frame  OutlineColor="Silver" HasShadow="True"   Margin="2,2"   BackgroundColor="Transparent" VerticalOptions="FillAndExpand" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds=".5,.5,1,1" >
                                <Label  HorizontalOptions="CenterAndExpand"   FormattedText="{Binding .,Converter={StaticResource ItemLogInfoConvertor}, Mode=OneWay}"   LineBreakMode="NoWrap"     />
                            </Frame>

                     </DataTemplate>
                </sfListView:SfListView.ItemTemplate>
                </sfListView:SfListView>


In ViewModel


 public Command SaveClick
        {
            get
            {
                return new Command(async () =>
                {
                    try
                    {
                        var success = await SaveData();

                        if (success == false)
                        {
var data= getData();
                          Items = new ObservableCollection<Item>(data);
                        }
                       
                    }
                    catch (Exception ex)
                    {

           
                    }

                });
            }
        }
  private ObservableCollection<Item> items;
        public ObservableCollection<Item> Items
        {
            get
            {
                if (items == null)
                    items = new ObservableCollection<Item>();

                return workoutSetWeightLogs;
            }
            set
            {
                if (value != null)
                {
                    items = value;                   
                    RaisePropertyChanged("Items"); // not sure if is even needed
                }
            }
        }

4 Replies

DB Dinesh Babu Yadav Syncfusion Team July 24, 2017 10:45 AM UTC

Hi Emil, 
 
Thank you for contacting Syncfusion support. 
 
We have checked the reported issue “ListViewItems are not updated in view when adding the underlying data at runtime” at our end with the latest SfListView version(v15.2.0.46). In the sample, we have added the data into the underlying collection(both initially zero items and adding N number of items) at runtime by both asynchronously and synchronously loading the data in a button click. Thus the items are added in UI as expected and we didn’t face any issue as reported. For your reference, we have attached the ensured sample at our end and you can download it from the below link. 
 
 
Could you please check with the above sample? If the issue still persist at your end, we request you to modify the above sample to reproduce the issue and revert us with the replication procedure. Also, could you please share the below information’s. So, that we could able to analyze the issue better and update you an appropriate solution.  
  
  • Could you please share the Xamarin Forms version?. We have ensured in Xamarin Forms v2.3.3.180.
  • Could you please share the SfListView version?. We have ensured in latest version (v15.2.0.46).
  • In which layout does the issue replicates either in LinearLayout or GridLayout or both?
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 
 



EM Emil July 25, 2017 01:00 PM UTC

Hi Dinesh,

using your example is just fine. I have achieved this also but problem is when I use a converter, change the value inside converter, it is not being reflected to UI until I scoll down and up or manually refresh the UI myself. I amended your sample and you will be able reproduce it. 

- I added a property called "IsCompleted", default=false

- I am binding all contacts at the page load.

- then when you click changecontacts button, you can see in the viewmodel, I amend first contact "Aiden" changing property IsCompleted=true; but this is not reflected to UI immediately unless I scroll down and up. I think that cells are cached and they need to be refreshed and scrolling down and up causes this refresh. How can I achieve this?


Thanks,


Emil


Attachment: Grouping_95e2ce74.7z


EM Emil July 27, 2017 01:09 PM UTC

Hi,

have you had a chance to look into this please? I appreciate for you help.

thanks,


Emil



DB Dinesh Babu Yadav Syncfusion Team July 27, 2017 04:44 PM UTC

Hi Emil,  
  
Sorry for the inconvenience caused.  
  
We could able to reproduce the reported issue at our end and this issue occurs due to custom converter is not triggered when property in the data model is changed at runtime. This is a Xamarin framework issue, so, we have logged a bug report to the Xamarin team regarding this issue. Please find the further details in the following link. 
 
 
Please let us know if you require further assistance.  
  
Regards,  
Dinesh Babu Yadav 
 


Loader.
Up arrow icon