xamarin forms - two way binding with a picker - why cant I update a picker from code behind?

后端 未结 2 1934
北荒
北荒 2021-01-28 22:38

My products page only shows \'Product Name\' and \'Quantity\', quantity isdisplayed/ binded to the picker.

For test purposes to get this working there is only 2 products

2条回答
  •  青春惊慌失措
    2021-01-28 23:22

    Your ProductModel class does not inherit from INotifyPropertyChanged interface, you’ll need to add the interface to your class and implement it, also making sure to raise the INotifyPropertyChanged.PropertyChanged event in Quantity setter.

    You might want to create a ProductViewModel at this point, as I’m not sure you want to add INotifyPropertyChanged to a POCO class like ProductModel.


    Please don't edit your question with a different one, open a new question. Your previous question might have helped someone else facing the same problem of UI not being updated when changing a property of a class that does not inherit from IPropertyChanged. My previous answer is now irrelevant to the new question, and will never benefit anyone else.

    For your new question, your Quantity is of type int and your picker items are of type string, changing Quantity type to string should help solving your issue, you can also use SelectedIndex instead of SelectedItem if the index of the items are matching.

    
        
            0
            1
            2
            3
            4
            5
            6
        
    
    

提交回复
热议问题