How can I use DataTemplateSelector for Android and iOS but not UWP?

Hi Syncfusion,
I recently learned about DataTemplateSelector for a SfComboBox. 

How can I have the DataTemplateSelector apply for Android and iOS but not for UWP?

Thanks,
Will

5 Replies 1 reply marked as answer

SS Suganya Sethuraman Syncfusion Team July 28, 2020 12:03 PM UTC

Hi Will,

Query: “How can I use DataTemplateSelector for Android and iOS but not UWP?”

We have checked the reported issue at our end. We are able to reproduce the issue at our end. The issue seems to be due to framework level of UWP when we update the Xamarin.Forms version 4.5 or above. Since Xamarin components like Button and Entry also have the same issues, we cannot find a fix in our side rather than updating the version. Please change the Target version of UWP project in our sample from 16299 to 17763 to resolve the issue at your end. Please have the sample,

Sample Link:  https://www.syncfusion.com/downloads/support/directtrac/general/ze/SfComboBox1145116266

Video Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataTemplateSelector_Video-2035114558

Please let me know, if you have any other concerns.

Regards,
Suganya Sethuraman
 



WA Will Autio July 28, 2020 04:11 PM UTC

Hello Suganya Sethuraman,

Thanks for your reply.
It seems that I did not phrase my question clearly.
Even when I changed the min target for Windows, I still get the error with getting what appears to be empty combobox when it is expanded. Unfortunately I can not replicate it in a demo app. 

It works well for Android (and I expect for iOS - I have not been able to test it there yet). I have been given revised requrements. For iOS and Android I am to change the text color based on data associated with the entries in the combobox. However for UWP, the text color can stay as it is - black.

One way I thought of doing that is to have two comboboxes called AnI (for android and iOS) with a DataTemplateSelector and another called Win without a DataTemplateSelector. If I am on and Android or iOS device AnI would be visible and Win would be invisible. And if I am on a Windows device, then only the Win would be visible. I expect that should work. 

However, I was wondering if there is a way to use the one ComboBox so that when I am on an Android or iOS device the DataTemplateSelector applies and when I am on a Windows device, the DataTemplateSelector is bypassed?

I appreciate your insight into this puzzle.

Regards,
Will Autio



SS Suganya Sethuraman Syncfusion Team July 29, 2020 08:49 AM UTC

Hi Will,

We have analyzed your requirement.
It has been achieved by specifically maintain the same template for UWP with platform specific condition.

Code snippet: 
        protected override DataTemplate OnSelectTemplate(object item, BindableObject container) 
        { 
            var message = item as MobileDetail; 
            if (message == null) 
                return null; 
            if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS) 
            { 
                return message.IsAffected ? SpecificDataTemplate : DefaultTemplate; 
            } 
            else 
            { 
                return DataTemplate; 
            } 
        } 


Please have the sample,

Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SfComboBox-790609727

Please let me know, if you have any other concerns.

Regards,
Suganya Sethuraman
 


Marked as answer

WA Will Autio July 30, 2020 05:20 PM UTC

Hi Suganya Sethuraman,

Brilliant. That works fine.
Thanks,
Will


SS Suganya Sethuraman Syncfusion Team August 3, 2020 05:09 AM UTC

Hi Will,

Thanks for the update.

Please get back to us if you need any further assistance.

Regards,
Suganya Sethuraman
 


Loader.
Up arrow icon