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

ItemTemplateSelector works in a strange way in Android

I'm using ItemTemplateSelector method to differentiate between the templates displayed for level 0 and 1, and also try to use the same concept to further differentiate between templates used inside a level when item is selected or not. In short, in UWP and iOS everything seems to be alright but not in Android where, when returning the templates for selected / deselected states, everything from the lines subject to selection /deselection vanishes.

The ItemTemplateSelector looks this way:
    public class ItemTemplateSelector : DataTemplateSelector
    {
        public DataTemplate Template1 { get; set; }
        public DataTemplate Template2 { get; set; }
        public DataTemplate Template3 { get; set; }
        public DataTemplate Template4 { get; set; }
        public ItemTemplateSelector()
        {
            Template1 = new DataTemplate(typeof(TemplateLevel0));
            Template2 = new DataTemplate(typeof(TemplateSelectLevel0));
            Template3 = new DataTemplate(typeof(TemplateLevel1));
            Template4 = new DataTemplate(typeof(TemplateSelectLevel1));
        }
        
        protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
        {
             var treeviewNode = item as TreeViewNode;
            if (treeviewNode == null)
                return null;
            Boolean IsChecked = (Boolean)treeviewNode.IsChecked;
            switch (treeviewNode.Level)
            {
                case 0:
                    if (IsChecked)
                    {
                        return Template2;
                    }
                    else
                    {
                        return Template1;
                    }
                case 1:
                    if (IsChecked)
                    {
                        return Template4;
                    }
                    else
                    {
                        return Template3;
                    }
                default:
                    return null;
            }
        }
    }
The idea behind is to add the selected line /item in the treeview as "checked" in the CheckedItems list using this code:
        private void treeView_SelectionChanged(object sender, ItemSelectionChangedEventArgs e)
        {
            _ExecuteItemSelection = false;
        }
        private async void treeView_SelectionChanging(object sender, ItemSelectionChangingEventArgs e)
        {
           if (_ExecuteItemDoubleTapped) return;
            if (_ExecuteItemSelection) return;
            _ExecuteItemSelection = true;

            var elem = e.AddedItems.FirstOrDefault();
            devaptreeView.CheckedItems.Clear();
            if (elem != null) devaptreeView.CheckedItems.Add(elem);
        }

Although looks unorthodox, works well in UWP and iOS, but not in Android. I all 3 OS's the IsChecked variable is correctly detected at the ItemTemplateSelector level, but some strange things happen when returning templates in Android. If you are not trying to select something, in Android, the level based template selection in ItemTemplateSelector is working as expected, only when executing the if (IsChecked) branch the code misbehave. 

Thank you


4 Replies

LN Lakshmi Natarajan Syncfusion Team December 12, 2019 01:38 PM UTC

Hi Constantin, 
 
Thank you for contacting Syncfusion support. 
 
We could able to replicate the reported issue from our end. We were currently validating the issue and provide you further details on tomorrow (December 13, 2019). We appreciate your patience until then. 


 
Regards, 
Lakshmi Natarajan 



LN Lakshmi Natarajan Syncfusion Team December 13, 2019 12:29 PM UTC

Hi Constantin, 
 
We have analyzed and we confirm that the reported issue `SelectedItem text is not visible when TemplateSelector used in TreeView is a defect. We have logged issue report for the same, we will fix the issue and include the issue fix in our weekly nuget which is planned to be rolled out on January 7, 2020. We appreciate your patience until then.  
You can track the status of this report through the following feedback link,  
 
 
Regards, 
Lakshmi Natarajan 
 



LN Lakshmi Natarajan Syncfusion Team January 8, 2020 04:50 AM UTC

Hi Constantin,                  
  
Sorry for the delay caused.   
  
We have fixed the reported issue “SelectedItem text is not visible when TemplateSelector used in TreeView”. We will include the issue fix in our next Weekly NuGet release which planned to roll out on January 14, 2020. We appreciate your patience until then.  
  
Please let us know if you need issue fix patch earlier. 
 
Regards,
Lakshmi Natarajan
 



LN Lakshmi Natarajan Syncfusion Team January 14, 2020 04:24 PM UTC

Hi Constantin,                    
      
We have fixed the reported issue “SelectedItem text is not visible when TemplateSelector used in TreeView” and included the issue fix in our latest Weekly NuGet release update version 17.4.0.43 which is available for download (nuget.org). 
  
We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you would require any further assistance. 
  
Regards, 
Lakshmi Natarajan   


Loader.
Live Chat Icon For mobile
Up arrow icon