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

ViewModel Property getting set twice and null sometimes

$
0
0

I am having a problem with my Xamarin forms UI.
On Appearing of a UI
on my VM i call a function that does this
public void OnAppearing()
{
Task.Run(() =>
{
SetDataAsync().ConfigureAwait(false);
});
}
In SetDataAsync It goes to a services pulls a list a program codes.
Inside of SerDataAsync It Sets the program codes in the VM property
I have these two lines
ProgramCodes = new ObservableCollection(newCode);
SelectedGasProgramCode = newCode.First();

  private ObservableCollection<string> _programCodes;
        public ObservableCollection<string> programCodes
        {
            get { return _programCodes; }
            set
            {
                    SetProperty(ref _programCodes, value);             
            }
        }

        private string _selectedProgramCode;
        public string SelectedProgramCode
        {
            get { return _selectedProgramCode; }
            set
            {
                    SetProperty(ref _selectedProgramCode, value);
            }
        }

When I put a break point at Set_SelectedProgramCode
I see it when I want to set the value in SetDataAsync which is what I expected. and I see that in the call stack
BUT then I see it called again by Xamarin.Forms.Picker.ResetItems . I am sure what I am doing is wrong. But I am not sure how to do it correctly. I want to set the picker AND decided which item is the default selected.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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