Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Best way to set a bound Picker SelectedIndex

$
0
0

Hello,
I have bound a Picker SelectedIndex to a public property of the ViewModel.
But when the user wants to edit an item of the model, he opens the page. Then I have to set the picker SelectedIndex to the value of the property of the item edited.
So I need to prevent the property to be modified by the Picker.
This is how I do. Is it the good way?

        private bool getPickerStarsSelectedIndex = false;
        public int PickerStarsSelectedIndex
        {
            get
            {
                getPickerStarsSelectedIndex = true;
                if (_currentSight.StarID > 0)
                    return convertStarIDtoPickerStarsSelectedIndex(_currentSight.StarID);
                else
                    return 0;
            }
            set
            {
                if (getPickerStarsSelectedIndex)
                    getPickerStarsSelectedIndex = false;
                else
                    _currentSight.StarID = convertPickerStarsSelectedIndexToStarID(value);
            }
        }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>