Like Charge ComboBox with a loaded list [XAML] [MVVM] [UWP]

0

is that I have a ComboBox in XAML and I have to do Binding to the ViewModel to load it with a query that I do of a table called "City" that has some fields id, Name, Country. but in the combo I'm only interested in showing the city, I think it goes like this but I do not know what I'm doing wrong, if I do the query the list is loaded, but not the Combo.

Combo Code:

<ComboBox Header="Ciudad" Width="245" ItemsSource="{x:Bind Ciudades}" SelectedIndex="{Binding CountCiudad, Mode=TwoWay}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Nombre}"/>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

The properties that I have are like this:

public List<Ciudad> Ciudades { get => ciudades; set => Set(ref ciudades, value); }
private List<Ciudad> ciudades;

and so I have the method:

public async void CargarCiudades(){
    this.Ciudades = new List<Ciudad>(await App.Repository.Ciudad.GetAsync());
}

I do not know why it does not load me, in the method the list is loaded, so I do not know if it's in the XAML where I'm failing

Image of the behavior of the method

    
asked by Wilmilcard 03.10.2018 в 22:35
source

1 answer

0

Remove this part of the binging

SelectedIndex="{Binding CountCiudad, Mode=TwoWay}"

Because CountCity may be causing an exception for IndexOutOfRange.

And if the memory does not fail me the list has to be an observable collection

    
answered by 03.10.2018 / 22:44
source