Xamarin Forms SfComboBox is not working well with Binding

Hi. I have a SfComboBox which get it's DataSource from a ViewModel context. Here is my code.
It simply has a collection of Person objects (with a string property Name )as DataSource and has a ItemTemplate . In my test on android it shows the text "OTHER LABEL" but the {Binding Name} does not work. On UWP platform it's like it's ignoring the ItemTemplate and Shows (BindingContext.ToString()). (Binding to Persons is okay but the ItemTemplate seems not to be working). Thanks

<sfComboBox:SfComboBox
            DataSource="{Binding Persons}"
            Watermark="Select an Area">
            <sfComboBox:SfComboBox.ItemTemplate>
                <DataTemplate>
                    <StackLayout Orientation="Horizontal">
                        <Label Text="{Binding Name}" />
                        <Label Text="OTHER LABEL" />
                    </StackLayout>
                </DataTemplate>
            </sfComboBox:SfComboBox.ItemTemplate>
</sfComboBox:SfComboBox>

3 Replies

PA Paul Anderson S Syncfusion Team September 5, 2018 12:34 PM UTC

Hi Morteza, 
 
Greetings from Syncfusion. 
 
Query: “Xamarin Forms SfComboBox is not working well with Binding” 
 
We have checked the reported issue. We are unable to reproduce the reported issue and we have created a sample based on a given code snippet. Please have the sample from the following link 
 
 
Could you please update Syncfusion.Xamarin.SfCombobox package into 16.2.0.50 version. 
 
Please let us know if you have any other concern. 
 
Regards, 
Paul Anderson 



MO morteza September 5, 2018 03:38 PM UTC

Thanks for your reply. I think I found the issue. 

The unwanted behavior happens when the "DataSource" property of "SfComboBox" is set to null and page appears.
In the sample you sent for me you initialize "EmployeeCollection" in ViewModel's constructor and populate it. While in my sample I wanted to initialize my Collection in another method which is called right after "Page.Appearing" event gets fired.
I simply initialized my collection in constructor of ViewModel and then the issue went away (Collection should not be null when page appears).

Though the issue seems to be fixed but I am still not sure if it was the reason.
Please inform me about the issue's reason if you made sure what caused the issue.
Thanks again for the sample.


PA Paul Anderson S Syncfusion Team September 6, 2018 12:08 PM UTC

Hi Morteza, 
 
Query1: The unwanted behavior happens when the "DataSource" property of "SfComboBox" is set to null and page appears. 
 
When the DataSource is set as null, items will be not be displayed when clicking the dropdownbutton since no items (collection) are available in the data source. 
 
Query2: Issue occured when I wanted to initialize my Collection in another method which is called right after "Page.Appearing" event gets fired. 
 
When initializing the collection after the "Page.Appearing", the values are passed to native UWP from the forms but the ItemTemplate view is not passed to the native UWP, So the blank view is show in the UWP. But we can achieve your requirement by initializing the collection in the ViewModel class constructor. 
 
Please let us know if you have any concern. 
 
Regards, 
Paul Anderson 


Loader.
Up arrow icon