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

SfTreeView strange behavior on ItemTemplate & Binding: after first population don't update the UI

Hi,

I've a Items that is an ObservableCollection<Item>.
Item class implement INotifyPropertyChanged and with other UI part it works.

With TreeView the first bind works fine. All node appear with the right data (an image and 2 labels).

But if I change a value (Text) of a Item (from antoher part of UI binded on the same Item object) the TreeView don't reflect the changes!
Either the Item belongs a expanded or collapsed node.
Meanwhile another UI part (Label) that is binded to the same prop of the same Item class, changes!?

Note:
in Debug, in the Output Window i saw this strange warnings, that disappear if I remove the binding in the ItemTemplate:
[0:] Binding: 'StructID' property not found on 'X4DNotes.Views.ItemsPage', target property: 'Xamarin.Forms.Label.Text'
[0:] Binding: 'Payload' property not found on 'X4DNotes.Views.ItemsPage', target property: 'Xamarin.Forms.Image.Source'
[0:] Binding: 'Text' property not found on 'X4DNotes.Views.ItemsPage', target property: 'Xamarin.Forms.Label.Text'

X4DNotes.Views.ItemsPage is the ContentPage that contain the TreeView ... but the binding is ONLY in the ItemTemplate, see next XAML.
And initial binding works on ItemTemplate!!???

DAMN!
while writing this .... I solved, I leave this thread in case someone should encounter the same problem

The problem was the implementation of INotifyPropertyChanged !

When I wroted I followed the official docs: INotifyPropertyChanged.PropertyChanged Event with this code:
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
var changed = PropertyChanged;
if (changed == null) return;
IsChanged = true;
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
and calling it according to docs:
public string Text { get => _Text; set { if (_Text != value) { _Text = value; OnPropertyChanged(); } } }
but with that code I got the issue discussed in this thread.

since I am a craftsman and very pragmatic I have tried this:
public string Text { get => _Text; set { if (_Text != value) { _Text = value; OnPropertyChanged("Text"); } } }
and with this code all WORKS FINE!!!


Thanks for attention.

PS: Syncfusion guys ... do think do you share this issue with MS?

Davide

XAML:
 <navigationdrawer:SfNavigationDrawer.DrawerContentView>
                <sf:SfTreeView x:Name="treeView" 
                               ItemsSource="{Binding Items}"
                               ChildPropertyName="Childs"
                               SelectionMode="Single"
                               SelectionChanging="TreeView_SelectionChanging"
                               SelectionChanged="TreeView_SelectionChanged"
                               NotificationSubscriptionMode="CollectionChange"
                               >
                    <sf:SfTreeView.ItemTemplate>
                        <DataTemplate>
                           <Grid Padding="2,0,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <StackLayout Orientation="Horizontal">
                                    <Label Text="{Binding StructID}" HorizontalTextAlignment="Start" FontAttributes="Bold"/>
                                    <Image Source="{Binding Payload,Converter={StaticResource PayLoadToImage}}" WidthRequest="48" 
                                                                      IsVisible="{Binding . , Converter={StaticResource ItemIsImage}}" Margin="4,0,0,0"/>
                                    <Label Text="{Binding Text}" Margin="2,0,0,0"/>
                                </StackLayout>
                            </Grid>
                        </DataTemplate>
                    </sf:SfTreeView.ItemTemplate>
                </sf:SfTreeView>
            </navigationdrawer:SfNavigationDrawer.DrawerContentView>
        </navigationdrawer:SfNavigationDrawer>

7 Replies

DA Davide July 12, 2019 05:51 PM UTC

UPDATE:
the problem perist in one case:
if the "Text" prop of the Item is "" the changes will NOT propagate

If the "Text" prop is already filled with a string the propagation goes well.
Davide.


DB Dinesh Babu Yadav Syncfusion Team July 15, 2019 10:01 AM UTC

Hi Davide, 
 
Thank you for contacting Syncfusion support. 
 
With the given details and code snippet, we have checked the reported issue in our sample. In the sample, we have changed a property value from “” to some text value at runtime and it was bind to an element in the ItemTemplate. But unfortunately the reported issue does not replicated at our end, the property value gets changed and updated in UI as expected. Please find the tested sample below, 
 
 
Could you please check with the above sample?. We suspect that the issue may occur at notification passing to the data model property. If the issue still persists, we suggest you to replicate the issue in the above sample and revert us with replication procedure which would highly help us to analyze the issue better and update you an appropriate solution. 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 



DA Davide July 15, 2019 12:03 PM UTC

Hi Dinesh,
I still to reproduce the issue in your example… but the example is NOT BUILDABLE.
Please give me a working Visual Studio Solution.

I use Visual Studio 2019 16.1.6, or if you prefere the 16.2.0 preview 3.

I deep investigate in the issue and i saw that if the node is expanded the added child have the issue, BUT if the node is collapsed (never opened before the Tree is drawed the 1st time) the child node react correctly (if I edit the source text the node reflect the changes).

UPDATE: the binding of a collapsed child node (node are added by code in a CurrentiNode.Childs , CurrentNode is any node in ItemSource collection) when the parent node was collapsed, continue to works WELL also if you expand the parent node and change the source value of binding.
BUT the siblings nodes added after the parent node was expanded got the ISSUE and they don't reflect the changes in binded prop.

The only explanation that comes to mind is that:
- if a child node is not showed right now the binging is TwoWay
- if a child is already showed the binding mode is OneTime
Is possible or I'm wrong?

This seems a control-in-deep-issue.

There is a way to obtain the SFTreeView sources, only for debugging?
Davide.
PS: please remember to send me a working (buildable) example to help you/me to understand the issue. Thank you.



DA Davide July 15, 2019 12:07 PM UTC

Attached the image of errors VS show me when try to build your example.

Note: I've already don the Restore of  NuGet pckgs

Here the text:

Severity Code Description Line File Project Suppression State
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.Core.XForms.Android`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.Core.XForms.Android`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.Core.XForms`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.Core.XForms`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.SfNavigationDrawer.XForms.Android`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.SfNavigationDrawer.XForms.Android`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.SfNavigationDrawer.XForms`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.SfNavigationDrawer.XForms`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.SfTreeView.XForms.Android`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.SfTreeView.XForms.Android`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Core`, referenced by `Syncfusion.SfTreeView.XForms`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Core`, or remove the reference to `Syncfusion.SfTreeView.XForms`.   TreeViewSample.Android 
Error  Can not resolve reference: `Xamarin.Forms.Xaml`, referenced by `TreeViewSample`. Please add a NuGet package or assembly reference for `Xamarin.Forms.Xaml`, or remove the reference to `TreeViewSample`.   TreeViewSample.Android 
Error  Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. 2 C:\VsProjs\R&D2019\Xamarin\synfusion\TreeViewSample-2063574089\TreeViewSample\TreeViewSample\TreeViewSample.Android\Resources\values\styles.xml TreeViewSample.Android 


Attachment: Syncfusione_TreeViewSample_errorsAnnotazione_20190715_135008_6d8c2828.zip


DB Dinesh Babu Yadav Syncfusion Team July 16, 2019 09:02 AM UTC

Hi Davide, 
 
Sorry for the inconvenience caused.  
 
We have checked the sample and found that the packages are not referred properly in sample. We have ensured the sample again and replaced now. Please find the latest sample from below link. 
 
 
Can you please check with the above sample whether issue reproduces in our sample also. We suspect that the issue may occur at notification passing to the data model property. If the issue persists, we suggest you to replicate the issue in above sample and revert us back with the replication procedure which will be help us to find the better solution. 
 
Please let us know if you have any concern. 
 
Regards, 
Dinesh Babu Yadav  



DA Davide July 16, 2019 10:08 AM UTC

Hi Dinesh, thanks. 
I will try ASAP.


DB Dinesh Babu Yadav Syncfusion Team July 16, 2019 12:25 PM UTC

Hi Davide, 
 
Thanks for the update. We will wait to hear from you. 
 
Regards, 
Dinesh Babu Yadav 


Loader.
Live Chat Icon For mobile
Up arrow icon