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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Picker cannot set SelectedItem with MVVM binding

Thread ID:

Created:

Updated:

Platform:

Replies:

147435 Sep 10,2019 08:32 PM UTC Sep 16,2019 06:33 AM UTC Xamarin.Forms 5
loading
Tags: SfPicker
Murat
Asked On September 10, 2019 08:32 PM UTC

Hi, 

I can get items from API and I know selected item but item is not set as selected with no error. List is filled properly and I can see (in debug) selected item is gathered in the same object. However binding not working. 

PS: I use MVVM.

Please see attached files. The abstract of the relavant part is below. Thanks in advance :)

ViewModel part; 

               if (response.Status)
            {
                IncomeDetail = JsonConvert.DeserializeObject<IncomeDetail>(response.Data.ToString());

                Item = IncomeDetail.Item;
                IncomeDetail.FinancialPlan.ID = FinancialPlanId;
                SelectedIncomeType = IncomeDetail.IncomeType;
                BudgetAmount = IncomeDetail.BudgetAmount;
                ActualAmount = IncomeDetail.ActualAmount;
                TargetPayDate = IncomeDetail.TargetPayDate;
                ActualPayDate = IncomeDetail.ActualPayDate;
                SelectedItemLevel = IncomeDetail.ItemLevel;
                Notes = IncomeDetail.Notes;
            }

Xaml part;  
                    <inputLayout:SfTextInputLayout
                        Grid.Row="5"
                        Grid.Column="1"
                        Grid.ColumnSpan="2"
                        ContainerType="Outlined"
                        Hint="Öncelik"
                        ReserveSpaceForAssistiveLabels="False">
                        <Picker
                            x:Name="pickerLevel"
                            ItemDisplayBinding="{Binding Name}"
                            ItemsSource="{Binding ItemLevel}"
                            SelectedItem="{Binding SelectedItemLevel}" />
                    </inputLayout:SfTextInputLayout>



Picker is not coming with Selected ItemLevel whereas I can see in debug mode.




Attachment: Picker_SelectedItem_Mvvm_6301eafd.zip

Muneesh Kumar G [Syncfusion]
Replied On September 12, 2019 06:25 AM UTC

Hi Murat, 
 
Greetings from Syncfusion.  
 
We have analyzed your code snippet and sample and you have used Xamarin.Forms Picker in your application. And also, some files missed in your attachment. So, please update us the complete sample, this would be helpful for us to give better solution in this.  
    
Thanks,   
Muneesh Kumar G.   
 


Murat
Replied On September 12, 2019 10:01 AM UTC

Hi Kumar, 

Since SfTextInputLayout, which I need for ContainerType prop, does not allow SfPicker, I used Xamarin.Forms Picker and cannot ensure that is it a bug or not? 

I have attached a very simple part of my issue (SettingsPage.xaml).
Just loading income types sourced from an API (ID and Name) and setting selected Item hardcoded which doesn't work (nothing coming as selected) 

Any help is appreciated. 


Attachment: Picker_SfTextInput_95b17122.zip

Ruba Shanmugam [Syncfusion]
Replied On September 12, 2019 01:46 PM UTC

Hi Murat,

Thanks for the update.

We have analyzed your query, you can resolve this issue in Picker by setting the selected item as like below code snippet

Code snippet:
 
                ItemLevel = new ObservableCollection<ItemLevel>();
                ItemLevel.Add(new ItemLevel() { ID = 1, Name = "Yüksek" });
                ItemLevel.Add(new ItemLevel() { ID = 2, Name = "Orta" });
                ItemLevel.Add(new ItemLevel() { ID = 3, Name = "Düşük" });

                var item = new ItemLevel() { ID = 2, Name = "Orta" };
            SelectedItemLevel = ItemLevel.Where(p => p.ID == item.ID).First();


Or you can use the selected index for display the selected item.We have created sample based on your code snippet.Please find the sample from below link:

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PickerSample-43957170    

Please let us know if you have any concern.

Regards,
Ruba S


Murat
Replied On September 13, 2019 12:54 PM UTC

Hi Ruba, 

You are great! It works like a clock ;) 

THANK YOU VERY MUCH 

Muneesh Kumar G [Syncfusion]
Replied On September 16, 2019 06:33 AM UTC

Hi Murat, 
 
Thanks for the update. 
  
We are glad to know that the given solution works. Please let us know if you need any further assistance. 
 
Thanks, 
Muneesh Kumar G. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon