Xamarin: Two picker controls, one dependent on another

0

I edit, thanks for the help @ Brian593.

I have the first drop-down and it detects me when I select another from the list, now I need the second drop-down to change its items depending on the first, I leave the code below:

public class DatosBaseViewModel : INotifyPropertyChanged
{

    ...

    #region Properties

    public ObservableCollection<UnidadObra> UnidadesObra { get; set; }
    public ObservableCollection<UnidadObraGrupo> UnidadesObraGrupo { get; set; }
    public UnidadObraGrupo SelectedUnidadObraGrupo { get; set; }
    int unidadObraGrupoSelectedIndex;
    public int UnidadObraGrupoSelectedIndex
    {
        get
        {
            return unidadObraGrupoSelectedIndex;
        }
        set
        {
            if (unidadObraGrupoSelectedIndex != value)
            {
                unidadObraGrupoSelectedIndex = value;

                // trigger some action to take such as updating other labels or fields
                OnPropertyChanged(nameof(UnidadObraGrupoSelectedIndex));
                SelectedUnidadObraGrupo = UnidadesObraGrupo[UnidadObraGrupoSelectedIndex];
            }
            UnidadesObra = new ObservableCollection<UnidadObra>(UnidadesObraTotal.Where(l => l.Grupo == SelectedUnidadObraGrupo.Cod));
        }
    }

    // Create the OnPropertyChanged method to raise the event
    protected void OnPropertyChanged(string name)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
    #endregion

    ...

To be more specific, the idea is that the UnidadObra drop-down will change depending on what has been selected in UnidadObraGrupo .

Thanks for your help.

    
asked by Dani Paredes 18.07.2018 в 11:44
source

1 answer

0

Use the MVVM pattern and the bindable picker control, when you change the first you notify the application the change an example you have it here link

    
answered by 18.07.2018 в 20:12