- Home
- Forum
- Xamarin.Forms
- Picker cannot set SelectedItem with MVVM binding
Picker cannot set SelectedItem with MVVM binding
Hi,


Attachment: Picker_SelectedItem_Mvvm_6301eafd.zip
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
SIGN IN To post a reply.
5 Replies
MK
Muneesh Kumar G
Syncfusion Team
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.
MU
Murat
September 12, 2019 10:01 AM UTC
Hi Kumar,
Attachment: Picker_SfTextInput_95b17122.zip
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
RS
Ruba Shanmugam
Syncfusion Team
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:
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
MU
Murat
September 13, 2019 12:54 PM UTC
Hi Ruba,
You are great! It works like a clock ;)
THANK YOU VERY MUCH
MK
Muneesh Kumar G
Syncfusion Team
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.
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
MU Murat
- Sep 10, 2019 08:32 PM UTC
- Sep 16, 2019 06:33 AM UTC