Reputation: 1267
Hi I'm using Visual Studio Enterprise and develop with Prism.Unity.Forms and Xamarin.Forms.
In my ViewModel I retrive from webservice my data (see this figure)
I would like retrieve this data into my View into ListView, but I can not have access to ListaEstadoCuenta, I can show "polizaId" and "estado"
this is the information in "ListaEstadoCuenta"
In my view I have the ListView:
Please help me how to display data "ListaEstadoCuenta" list in the Labels, I hope your help
Upvotes: 0
Views: 769
Reputation: 14760
ListaEstadoCuenta
is a List. This means you have to specify the item in the bindings of your Labels. E.g. for the first Item:
<ViewCell>
<!-- ... -->
<Label Text="{Binding ListaEstadoCuenta[0].Comprobante}" />
<Label Text="{Binding ListaEstadoCuenta[0].FechaDoc}" />
<!-- ... -->
</ViewCell>
If you want to show list items in one Label, you have to use Converters to combine the values:
Value converter
public class StringConcatenationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is IEnumerable<EstadoCuentaDetalle>)
{
return string.Join(", ", ((IEnumerable<EstadoCuentaDetalle>)value).Select(x => x.Combrobante));
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Resource in your Page
You have to adjust the local namespace xmlns:local
to refer your assembly name.
<ContentPage ...
xmlns:local="clr-namespace:FormsTest;assembly=FormsTest">
<ContentPage.Resources>
<ResourceDictionary>
<local:StringConcatenationConverter x:Key="concatConverter"></local:StringConcatenationConverter>
</ResourceDictionary>
</ContentPage.Resources>
Binding
<Label Text="{Binding ListaEstadoCuenta, Converter={x:StaticResource Key=concatConverter}}" />
Upvotes: 1